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

Parsing of Postgres array slice operator throw error #624

Closed
wirekang opened this issue Jul 19, 2023 · 4 comments · Fixed by #652
Closed

Parsing of Postgres array slice operator throw error #624

wirekang opened this issue Jul 19, 2023 · 4 comments · Fixed by #652
Labels

Comments

@wirekang
Copy link

Input data

select (array_agg("test"))[:5] as "test" from "user"

Actual Output

Parse error: Unexpected ":5] as "te" at line 1 column 28```

Usage

@nene
Copy link
Collaborator

nene commented Jul 19, 2023

Thanks for reporting. That's definitely a bug in the parser.

@nene nene changed the title [FORMATTING] Postgres array slice Parsing of Postgres array slice operator throw error Jul 19, 2023
@wirekang
Copy link
Author

I'm wondering how this issue can be solved. It seems that single parser handles all dialect.

@nene
Copy link
Collaborator

nene commented Oct 23, 2023

You're correct @wirekang. The formatter has a very rudimentary parser which is used for all dialects. There are some options passed to the lexer to define which dialect supports which keywords and operators.

So a simple way to fix this error is to add : to the list of Postgres operators. Additionally should add it to formatOptions.alwaysDenseOperators, so it won't be formatted with spaces around it.

Unfortunately there's also a bug with parenthesis formatting, so we'd end up with the following:

select
  (array_agg("test")) [:5] as "test"
from
  "user"

But definitely better than crashing :)

@nene
Copy link
Collaborator

nene commented Oct 23, 2023

Fixed now in 13.0.1

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

Successfully merging a pull request may close this issue.

2 participants