Skip to content

PostgreSQL, DuckDB, Spark, Databricks: Accept a comparison in the BETWEEN lower bound - #2665

Merged
LucaCappelletti94 merged 4 commits into
mainfrom
between-low-bound-comparison
Oct 25, 2026
Merged

LucaCappelletti94 merged 4 commits into
mainfrom
between-low-bound-comparison

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Follow-up to #2664, which this PR is stacked on.

PostgreSQL, DuckDB and Spark accept one comparison in the lower bound of a BETWEEN, as in x BETWEEN 1 > 0 AND y, but reject IS, LIKE or a nested BETWEEN there. PostgreSQL 16 and DuckDB 1.4.4 run SELECT true BETWEEN 1 > 0 AND true, true BETWEEN 1 <> 2 AND true and true BETWEEN 1 + 1 >= 2 AND true, and both reject true BETWEEN 1 = 1 = true AND true with a syntax error. Spark's grammar parses the bound as a valueExpression, which includes comparison (https://github.com/apache/spark/blob/master/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4). These dialects stopped the bound before the comparison and failed with Expected: AND, found: >.

A single precedence threshold cannot express this, because PostgreSQL ranks LIKE and BETWEEN above comparisons. A new dialect method, supports_comparison_in_between_low_bound, lets the parser read one comparison after the bound, with its right side parsed at BETWEEN precedence. It is enabled for PostgreSQL, DuckDB, Spark, Databricks and the generic dialect. Tests check the parsed bound and the rejected forms in those dialects, and the unchanged error everywhere else.

@LucaCappelletti94
LucaCappelletti94 added this pull request to stack #2666 October 17, 2026 16:57
@codecov-commenter

codecov-commenter commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.22%. Comparing base (fcd2328) to head (5e0d022).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2665      +/-   ##
==========================================
+ Coverage   82.21%   82.22%   +0.01%     
==========================================
  Files          42       42              
  Lines       35320    35343      +23     
  Branches    35320    35343      +23     
==========================================
+ Hits        29037    29060      +23     
  Misses       2716     2716              
  Partials     3567     3567              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from ec5975a to b39c116 Compare October 17, 2026 18:52
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch 2 times, most recently from 285aa80 to 7e1f7f3 Compare October 20, 2026 12:10
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 7e1f7f3 to 5e2b861 Compare October 20, 2026 12:32
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 5e2b861 to 0146c69 Compare October 21, 2026 07:38
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 0146c69 to f745aee Compare October 23, 2026 22:20
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from f745aee to 34b0fca Compare October 24, 2026 06:44
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 34b0fca to 325c9a8 Compare October 24, 2026 07:16
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 325c9a8 to 12be3df Compare October 24, 2026 08:44
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 0f9c994 to d2b89cd Compare October 24, 2026 13:29
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from d2b89cd to 3b4d09f Compare October 24, 2026 14:06
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 3b4d09f to 8670d82 Compare October 24, 2026 14:25
Comment thread tests/sqlparser_sqlite.rs
))
);

assert_eq!(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we instead update the test to show what happens with this statement rather than deleting it now? I assume it parses correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case is already covered in parse_comparison_in_between_low_bound, that's why I dropped it.

Base automatically changed from sqlite-between-operand-precedence to main October 25, 2026 16:32
@LucaCappelletti94
LucaCappelletti94 force-pushed the between-low-bound-comparison branch from 8670d82 to 5e0d022 Compare October 25, 2026 16:52
@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 25, 2026
Merged via the queue into main with commit 72ce6a8 Oct 25, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants