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

Crash with complex expressions inside BETWEEN #523

Closed
kdeun1 opened this issue Nov 16, 2022 · 3 comments · Fixed by #525
Closed

Crash with complex expressions inside BETWEEN #523

kdeun1 opened this issue Nov 16, 2022 · 3 comments · Fixed by #525
Labels

Comments

@kdeun1
Copy link

kdeun1 commented Nov 16, 2022

Describe the bug
A certain postgresql query statement causes a "script error" since version 10.0.0.
It doesn't happen in version 9.2.0.

Expected behavior
It should work fine on all versions.

Actual behavior
[NORMAL QUERY]

with A_TABLE as (
select
  1 as a
  ,2 as b
  ,now() as c
union all
select
  1 as a
  ,6 as b
  ,now() - interval'1 minute' as c
union all
select
  1 as a
  ,6 as b
  ,now() - interval'1 day' as c
)
select * from A_TABLE
where	a > 0
and		b > 0
and		c between (now() - interval'1 hour') and now()

[OTHER QUERY]

with A_TABLE as (
select
  1 as a
  ,2 as b
  ,now() as c
union all
select
  1 as a
  ,6 as b
  ,now() - interval'1 minute' as c
union all
select
  1 as a
  ,6 as b
  ,now() - interval'1 day' as c
)
select * from A_TABLE
where	a > 0
and		b > 0
and		c between now() - interval'1 hour' and now()

The above jsfiddle environment is version 10.0.0.
When testing with a 'NORMAL QUERY' and an 'OTHER QUERY', the results of the two queries are different.
There is a difference of one parenthesis in the between clause!

option object used in jsfiddle

option : {
  language: 'postgresql',
  tabWidth: 2,
  keywordCase: 'upper',
  linesBetweenQueries: 2,
}
version <= 9.2.0 > 10.0.0
NORMAL QUERY O O
OTHER QUERY O script error

Usage
How are you calling / using the library? npm install
What SQL language(s) does this apply to? postgresql
Which SQL Formatter version are you using? 9.2.0 vs. 10.0.0

@kdeun1 kdeun1 added the bug label Nov 16, 2022
@kdeun1 kdeun1 changed the title Issue Title Here Parentheses bug since version 9.2.0 Nov 16, 2022
@nene
Copy link
Collaborator

nene commented Nov 16, 2022

Thanks for reporting. It's really the same bug as #500

Will close this as duplicate.

@nene nene closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2022
@nene
Copy link
Collaborator

nene commented Nov 17, 2022

After further investigation I see it's a slightly different bug from #500. It boils down to supporting more complex expressions inside BETWEEN, like:

SELECT 5 BETWEEN 1 + 2 AND 10 + 8

It's also simpler to fix.

@nene nene reopened this Nov 17, 2022
@nene nene changed the title Parentheses bug since version 9.2.0 Crash with complex expressions inside BETWEEN Nov 17, 2022
@nene nene closed this as completed in #525 Nov 17, 2022
@nene
Copy link
Collaborator

nene commented Nov 17, 2022

This should now be fixed in 12.0.2 release

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