Skip to content

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

Open
LucaCappelletti94 wants to merge 1 commit into
sqlite-between-operand-precedencefrom
between-low-bound-comparison
Open

LucaCappelletti94 wants to merge 1 commit 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

❌ Patch coverage is 79.16667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.26%. Comparing base (1dbf078) to head (b39c116).

Files with missing lines Patch % Lines
src/dialect/spark.rs 0.00% 3 Missing ⚠️
src/parser/mod.rs 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@                        Coverage Diff                         @@
##           sqlite-between-operand-precedence    #2665   +/-   ##
==================================================================
  Coverage                              81.25%   81.26%           
==================================================================
  Files                                     42       42           
  Lines                                  33916    33939   +23     
  Branches                               33916    33939   +23     
==================================================================
+ Hits                                   27560    27579   +19     
- Misses                                  2792     2795    +3     
- Partials                                3564     3565    +1     

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