Skip to content

SQLite: Group LIKE, GLOB, MATCH and REGEXP with = - #3070

Merged
LucaCappelletti94 merged 3 commits into
mainfrom
upstream/sqlite-like-glob-precedence
Dec 1, 2026
Merged

LucaCappelletti94 merged 3 commits into
mainfrom
upstream/sqlite-like-glob-precedence

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Under SQLiteDialect, a GLOB 'p' = 1 parsed as a GLOB ('p' = 1). SQLite's grammar puts LIKE, GLOB, MATCH and REGEXP on the same left-associative level as = and <> (parse.y, %left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ), and sqlite3 returns 1 for SELECT 'a' GLOB 'a' = 1, which only the left-grouped reading gives. This came up in review on #3043 (comment).

The dialect ranked Precedence::Like one step below Precedence::Eq, so the pattern operand absorbed a following =, <>, BETWEEN or IN. Moving Precedence::Like to the level of Precedence::Eq in SQLiteDialect::prec_value regroups every operator that takes its level from that lookup, the NOT forms and the ESCAPE operand included. Other dialects keep their own tables.

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

codecov-commenter commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.64%. Comparing base (540e398) to head (4073f57).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3070   +/-   ##
=======================================
  Coverage   83.64%   83.64%           
=======================================
  Files          42       42           
  Lines       35833    35833           
  Branches    35833    35833           
=======================================
  Hits        29974    29974           
  Misses       2418     2418           
  Partials     3441     3441           

☔ 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 upstream/sqlite-like-glob-precedence branch from c35201a to b2f9fa5 Compare December 1, 2026 11:06

@zommiommy zommiommy left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sent my concerns in private and luca fixed them, lgtm.
for documentation sake, my concerns were:

1. A trailing ESCAPE after a regrouped pattern becomes a column alias. Once LIKE stops before = or IN, the LIKE parser never sees the trailing ESCAPE, so it falls through to SQLiteDialect::is_column_alias, which accepts it:

SELECT 'a' LIKE 'b' = 0 ESCAPE      -- main: parse error; this PR: alias "ESCAPE"
SELECT 'a' LIKE 'b' IN (0) ESCAPE   -- same

sqlite3 rejects both with near "ESCAPE": syntax error. Accepting ESCAPE as an alias is older (item 7); this PR makes it reachable after a pattern. Adding Keyword::ESCAPE to the reject list in is_column_alias should fix both while keeping AS "ESCAPE" working.

2. A few groupings this PR changes aren't pinned by the matrix. On main, each of these parses with the trailing operator folded into the pattern; here they group left:

  • a LIKE b IN (c)
  • a LIKE b BETWEEN c AND d
  • a NOT REGEXP b = c (NOT REGEXP builds Expr::RLike through the generic NOT path, not the SQLite REGEXP hook)
  • a NOT LIKE b ESCAPE c <> d

The test below also asserts the mirrored a = b NOT REGEXP c as a control; it groups as (a = b) NOT REGEXP c on main too.

@LucaCappelletti94

Copy link
Copy Markdown
Contributor Author

Thanks @zommiommy for the review, I will be merging this now, and later #@3043 after most likely rebasing it.

cc @alamb

@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 6ac24a8 Dec 1, 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