Skip to content

Reject unquoted reserved keywords as table names - #2633

Merged
LucaCappelletti94 merged 6 commits into
apache:mainfrom
LucaCappelletti94:reject-on-as-table-name
Oct 24, 2026
Merged

LucaCappelletti94 merged 6 commits into
apache:mainfrom
LucaCappelletti94:reject-on-as-table-name

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

SELECT * FROM t JOIN ON parses in every dialect, with ON taken as a table name, while PostgreSQL rejects it with syntax error at or near "ON". This enforces Dialect::is_table_factor at the table name position and adds ON to RESERVED_FOR_TABLE_FACTOR, so unquoted INTO, LIMIT, HAVING, WHERE and ON stop being table names. Quoted forms still parse.

Dialects whose documentation leaves one of these words unreserved keep accepting it.

That covers every keyword in ClickHouse and LIMIT in Databricks, Hive, MSSQL and Oracle. Snowflake's own list now applies to table names too, so parse_count_wildcard renames its Order table. I hope I have covered all of the dialects, as I am not too familiar with some.

#2629 pins today's error for SELECT * FROM users |> JOIN ON users.id = orders.user_id, and this changes it to Expected: table name, found: ON. Whichever of the two merges second updates that pin.

@codecov-commenter

codecov-commenter commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.97%. Comparing base (7ab6bfa) to head (badd49b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2633      +/-   ##
==========================================
+ Coverage   81.95%   81.97%   +0.01%     
==========================================
  Files          42       42              
  Lines       34702    34717      +15     
  Branches    34702    34717      +15     
==========================================
+ Hits        28440    28458      +18     
+ Misses       2735     2732       -3     
  Partials     3527     3527              

☔ 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 added the waiting on reviewer PR needs to be reviewed label Oct 15, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the reject-on-as-table-name branch 2 times, most recently from 3365ebe to 27c1a46 Compare October 18, 2026 14:18

@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.

Two non-blocking comments inline.

Comment thread src/parser/mod.rs Outdated
} else {
Keyword::NoKeyword
};
if !self.dialect.is_table_factor(&peek_keyword, self) {

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.

This calls is_table_factor before the keyword is consumed, while the trailing-comma caller in parse_table_with_joins calls it after next_token(). Snowflake's override peeks past the keyword for LIMIT <n> and TABLE(, so both arms are no-ops here. It still works because TABLE( is handled earlier and LIMIT is not in Snowflake's list. Worth either consuming and prev_token() like the comma site, or documenting the expected position on the trait, so the next lookahead override does not diverge.

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 keyword is now consumed before is_table_factor and restored with prev_token(), the same way as at the trailing comma site.

Comment thread tests/sqlparser_common.rs
#[test]
fn parse_count_wildcard() {
verified_only_select("SELECT COUNT(*) FROM Order WHERE id = 10");
verified_only_select("SELECT COUNT(*) FROM orders WHERE id = 10");

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.

This rename shows the change goes beyond ON: Snowflake's whole table-factor list now applies at the table position, and Generic rejects the five words too. Both match the docs, but they should be called out as breaking in the description/changelog.

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.

Unfortunately breaking changes are so common that it is almost a given that all versions are breaking versions. I hope we'll reach stability at some point, which is also why I am adding the fuzzers to accelerate that process as much as possible.

@s5dsn-eqee s5dsn-eqee 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.

LGTM!

@LucaCappelletti94

Copy link
Copy Markdown
Contributor Author

Thanks @s5dsn-eqee and @sabir-akhadov-localstack for the reviews!

cc @alamb

@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 24, 2026
Merged via the queue into apache:main with commit 8b06593 Oct 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants