Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several PostgreSQL operators are incorrectly split in two #52

Open
Diggsey opened this issue Sep 10, 2024 · 3 comments
Open

Several PostgreSQL operators are incorrectly split in two #52

Diggsey opened this issue Sep 10, 2024 · 3 comments

Comments

@Diggsey
Copy link

Diggsey commented Sep 10, 2024

Some examples I've encountered:

Before After
<-> < ->
<=> <= >
&& & &
@> @ >

There are probably many more. I think the formatter should avoid splitting adjacent symbols like this entirely.

@pnezis
Copy link

pnezis commented Oct 10, 2024

Some other examples that are wrongly split:

SELECT
  left <@ right,
  left << right,
  left >> right,
  left &< right,
  left &> right,
  left -|- right,
  @@ left,
  @-@ left,
  left <-> right,
  left <<| right,
  left |>> right,
  left &<| right,
  left |>& right,
  left <^ right,
  left >^ right,
  ?- left,
  left ?-| right,
  left ?|| right,
  left ~= right

Notice that this is only a tiny subset of postgres supported operators. You can get the full list by running

select * from pg_operator;

Additionally you are allowed to create your own operator through CREATE OPERATOR. The allowed operator characters are + - * / < > = ~ ! @ # % ^ & | ?`.

I agree with @Diggsey that the tokenizer should avoid splitting sequences of the above symbols in order to be safe. Currently it breaks queries using such operators.

@akoutmos
Copy link

akoutmos commented Nov 4, 2024

With #57 merged in I think this issue is solved. Any chance we could get a release so I can update my library that depends on sqlformat-rs? Really appreciate the effort you put into this library!

@shssoichiro
Copy link
Owner

Pushed a new release, please let me know if this is still an issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants