Skip to content

Commit

Permalink
Fix quoted identifier regression edge-case with "from" in SELECT (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie authored Jul 21, 2024
1 parent 028ada8 commit 71dc966
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10331,7 +10331,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 @@ -9005,7 +9005,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 @@ -9038,11 +9038,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

0 comments on commit 71dc966

Please sign in to comment.