Skip to content

SQLite: Bind <, <=, > and >= tighter than = - #2678

Merged
alamb merged 4 commits into
mainfrom
sqlite-comparison-precedence
Oct 23, 2026
Merged

alamb merged 4 commits into
mainfrom
sqlite-comparison-precedence

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

SQLite's operator table puts <, <=, > and >= one level above =, ==, <>, !=, IS, IN, LIKE and BETWEEN (https://www.sqlite.org/lang_expr.html#operators_and_parse_affecting_attributes). So a = b < c means a = (b < c): SQLite 3.51.1 evaluates SELECT 2 = 1 < 3 to 0, which only holds for 2 = (1 < 3). The SQLite dialect used a single level for all comparisons and parsed it as (a = b) < c.

SQLiteDialect now returns a separate precedence for <, <=, > and >=. Since the default table has no free value between = and the bitwise operators, the dialect overrides prec_value with the default levels shifted up by one above =. Other dialects are unchanged: PostgreSQL 16 and DuckDB 1.4.4 reject 2 = 1 < 3 outright, so there is no grouping to match there. Tests check the tree for each pairing, IN and BETWEEN against <, and that every other dialect still parses a = b < c as (a = b) < c.

@LucaCappelletti94 LucaCappelletti94 added bug Something isn't working SQLite labels Oct 18, 2026
@codecov-commenter

codecov-commenter commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.55%. Comparing base (28e9868) to head (ea04fc6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2678      +/-   ##
==========================================
+ Coverage   81.54%   81.55%   +0.01%     
==========================================
  Files          42       42              
  Lines       34239    34258      +19     
  Branches    34239    34258      +19     
==========================================
+ Hits        27920    27939      +19     
  Misses       2770     2770              
  Partials     3549     3549              

☔ 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 sqlite-comparison-precedence branch from 691ec44 to 9f2dc0b Compare October 21, 2026 07:54
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-comparison-precedence branch from 9f2dc0b to ea04fc6 Compare October 23, 2026 22:32
@alamb
alamb added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit d112446 Oct 23, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working SQLite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants