Skip to content

SQLite: Accept fallback keywords as implicit column aliases - #2682

Open
LucaCappelletti94 wants to merge 3 commits into
mainfrom
sqlite-keyword-aliases
Open

LucaCappelletti94 wants to merge 3 commits into
mainfrom
sqlite-keyword-aliases

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

SQLite lets most keywords serve as names: its grammar declares a %fallback ID list (https://sqlite.org/src/file?name=src/parse.y) and its keyword page describes the fallback (https://www.sqlite.org/lang_keywords.html). So SELECT a view FROM t or SELECT 1 offset alias the column as view or offset, and SQLite 3.51.1 runs them. The SQLite dialect rejected 13 such keywords as implicit aliases: ANALYZE, CLUSTER, DISTRIBUTE, EXCLUDE, EXPLAIN, FETCH, LATERAL, MINUS, OFFSET, SORT, TOP, VIEW and WITH.

In order to add support for these, SQLiteDialect now overrides is_column_alias and only refuses the keywords that start the next clause (FROM, WHERE, GROUP, ORDER, LIMIT, the set operators, RETURNING, VALUES, INTO, SELECT). SQLite also only reads OVER as a keyword when ( or a name follows (analyzeOverKeyword in https://sqlite.org/src/file?name=src/tokenize.c), so SELECT f() OVER aliases the result as OVER. A new dialect method, supports_over_keyword_as_column_alias, enables that for SQLite. Run against every keyword in this crate, as SELECT 1 <kw> and SELECT 1 <kw> FROM t, the SQLite dialect now matches SQLite on 26 more forms and accepts nothing new that SQLite rejects. Two common tests that relied on WITH and FETCH ending a select list now skip SQLite.

@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 (fb7ed0a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2682      +/-   ##
==========================================
+ Coverage   81.52%   81.53%   +0.01%     
==========================================
  Files          42       42              
  Lines       34205    34226      +21     
  Branches    34205    34226      +21     
==========================================
+ Hits        27885    27907      +22     
  Misses       2770     2770              
+ Partials     3550     3549       -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.

@sabir-akhadov-localstack sabir-akhadov-localstack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One non-blocking comment inline.

Comment thread src/parser/mod.rs Outdated
Token::SingleQuotedString(_) | Token::DoubleQuotedString(_)
),
};
if self.dialect.supports_over_keyword_as_column_alias() && !next_is_window_name {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is_column_alias runs here with the parser still positioned on the candidate token, while parse_optional_alias_inner consumes it before calling the hook, so overrides that peek ahead (Snowflake's looks at the token after EXCEPT/RETURNING/LIMIT) see a different position at this site. The result is discarded unless supports_over_keyword_as_column_alias() is true, so nothing breaks today, but checking the flag before the lookahead would skip it for every other dialect and keep the position mismatch from biting a dialect that enables the flag later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The lookahead now runs only when supports_over_keyword_as_column_alias() is true, so other dialects never reach it.

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.

4 participants