Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,11 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[Keyword] = &[
Keyword::TABLESAMPLE,
Keyword::FROM,
Keyword::OPEN,
Keyword::INSERT,
Keyword::UPDATE,
Keyword::DELETE,
Keyword::EXEC,
Keyword::EXECUTE,
];

/// Can't be used as a column alias, so that `SELECT <expr> alias`
Expand Down
17 changes: 17 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,23 @@ fn parse_select_with_table_alias() {
);
}

#[test]
fn parse_consecutive_queries() {
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.

Not sure what the best approach here is, or if there's even a better solution apart from disallowing any unquoted keyword as an alias

Copy link
Copy Markdown
Contributor Author

@aharpervc aharpervc May 8, 2025

Choose a reason for hiding this comment

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

It turns out doing that seems reasonable and reduces ambiguity. Dialects that require semicolon delimiters remain unaffected, but dialects where it's optional would need to quote the keyword as an identifier. That seems completely reasonable from a parser perspective.

I'm willing to drop the commit that added keywords to RESERVED_FOR_TABLE_ALIAS since this approach addresses that concern.

let select_then_exec = "SELECT * FROM deleted; EXECUTE my_sp 'some', 'params'";
let _ = all_dialects()
.parse_sql_statements(select_then_exec)
.unwrap();
let _ = all_dialects_not_requiring_semicolon_statement_delimiter()
.statements_without_semicolons_parse_to(select_then_exec, "");

let select_then_update = "SELECT 1 FROM x; UPDATE y SET z = 1";
let _ = all_dialects()
.parse_sql_statements(select_then_update)
.unwrap();
let _ = all_dialects_not_requiring_semicolon_statement_delimiter()
.statements_without_semicolons_parse_to(select_then_update, "");
}

#[test]
fn parse_analyze() {
verified_stmt("ANALYZE TABLE test_table");
Expand Down
Loading