Skip to content

Fix quoted identifier regression edge-case with "from" in SELECT #1346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10309,7 +10309,7 @@ impl<'a> Parser<'a> {
Expr::Wildcard => Ok(SelectItem::Wildcard(
self.parse_wildcard_additional_options()?,
)),
Expr::Identifier(v) if v.value.to_lowercase() == "from" => {
Expr::Identifier(v) if v.value.to_lowercase() == "from" && v.quote_style.is_none() => {
parser_err!(
format!("Expected an expression, found: {}", v),
self.peek_token().location
Expand Down
11 changes: 8 additions & 3 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8959,7 +8959,7 @@ fn parse_non_latin_identifiers() {

#[test]
fn parse_trailing_comma() {
// At the moment, Duck DB is the only dialect that allows
// At the moment, DuckDB is the only dialect that allows
// trailing commas anywhere in the query
let trailing_commas = TestedDialects {
dialects: vec![Box::new(DuckDbDialect {})],
Expand Down Expand Up @@ -8992,11 +8992,16 @@ fn parse_trailing_comma() {
);

trailing_commas.verified_stmt("SELECT album_id, name FROM track");

trailing_commas.verified_stmt("SELECT * FROM track ORDER BY milliseconds");

trailing_commas.verified_stmt("SELECT DISTINCT ON (album_id) name FROM track");

// check quoted "from" identifier edge-case
trailing_commas.one_statement_parses_to(
r#"SELECT "from", FROM "from""#,
r#"SELECT "from" FROM "from""#,
);
trailing_commas.verified_stmt(r#"SELECT "from" FROM "from""#);

// doesn't allow any trailing commas
let trailing_commas = TestedDialects {
dialects: vec![Box::new(GenericDialect {})],
Expand Down
Loading