Skip to content

Crash with complex expressions inside BETWEEN #523

@kdeun1

Description

@kdeun1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions