Skip to content

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

Open
LucaCappelletti94 wants to merge 2 commits into
mainfrom
sqlite-comparison-precedence
Open

LucaCappelletti94 wants to merge 2 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.32%. Comparing base (ada8314) to head (691ec44).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2678      +/-   ##
==========================================
+ Coverage   81.28%   81.32%   +0.04%     
==========================================
  Files          42       42              
  Lines       33920    34000      +80     
  Branches    33920    34000      +80     
==========================================
+ Hits        27571    27651      +80     
  Misses       2785     2785              
  Partials     3564     3564              

☔ 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 922069d to ef09b11 Compare October 18, 2026 14:17
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