Skip to content

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

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

LucaCappelletti94 wants to merge 3 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.53%. Comparing base (424378c) to head (9f2dc0b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2678      +/-   ##
==========================================
+ Coverage   81.52%   81.53%   +0.01%     
==========================================
  Files          42       42              
  Lines       34205    34224      +19     
  Branches    34205    34224      +19     
==========================================
+ Hits        27885    27904      +19     
  Misses       2770     2770              
  Partials     3550     3550              

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