Skip to content

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

Open
LucaCappelletti94 wants to merge 2 commits into
sqlite-between-operand-precedencefrom
between-low-bound-comparison
Open

LucaCappelletti94 wants to merge 2 commits into
sqlite-between-operand-precedencefrom
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 81.33%. Comparing base (9f9b65e) to head (5e2b861).

Additional details and impacted files
@@                          Coverage Diff                          @@
##           sqlite-between-operand-precedence    #2665      +/-   ##
=====================================================================
+ Coverage                              81.32%   81.33%   +0.01%     
=====================================================================
  Files                                     42       42              
  Lines                                  33983    34006      +23     
  Branches                               33983    34006      +23     
=====================================================================
+ Hits                                   27636    27659      +23     
  Misses                                  2785     2785              
  Partials                                3562     3562              

☔ 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
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.

2 participants