Skip to content

Reject unquoted reserved keywords as table names - #2633

Open
LucaCappelletti94 wants to merge 3 commits into
apache:mainfrom
LucaCappelletti94:reject-on-as-table-name
Open

LucaCappelletti94 wants to merge 3 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.31%. Comparing base (ada8314) to head (488c3ea).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2633      +/-   ##
==========================================
+ Coverage   81.28%   81.31%   +0.03%     
==========================================
  Files          42       42              
  Lines       33920    33965      +45     
  Branches    33920    33965      +45     
==========================================
+ Hits        27571    27619      +48     
+ Misses       2785     2782       -3     
  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 added the waiting on reviewer PR needs to be reviewed label Oct 15, 2026

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

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.

3 participants