Skip to content

Commit

Permalink
Fix parsing of COLLATE after parentheses in expressions (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Azzolini committed May 25, 2022
1 parent 901f5b9 commit 0fa812b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,18 @@ impl<'a> Parser<'a> {
};
self.expect_token(&Token::RParen)?;
if !self.consume_token(&Token::Period) {
return Ok(expr);
Ok(expr)
} else {
let tok = self.next_token();
let key = match tok {
Token::Word(word) => word.to_ident(),
_ => return parser_err!(format!("Expected identifier, found: {}", tok)),
};
Ok(Expr::CompositeAccess {
expr: Box::new(expr),
key,
})
}
let tok = self.next_token();
let key = match tok {
Token::Word(word) => word.to_ident(),
_ => return parser_err!(format!("Expected identifier, found: {}", tok)),
};
Ok(Expr::CompositeAccess {
expr: Box::new(expr),
key,
})
}
Token::Placeholder(_) => {
self.prev_token();
Expand Down
9 changes: 9 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,15 @@ fn parse_collate() {
);
}

#[test]
fn parse_collate_after_parens() {
let sql = "SELECT (name) COLLATE \"de_DE\" FROM customer";
assert_matches!(
only(&all_dialects().verified_only_select(sql).projection),
SelectItem::UnnamedExpr(Expr::Collate { .. })
);
}

#[test]
fn parse_select_string_predicate() {
let sql = "SELECT id, fname, lname FROM customer \
Expand Down

0 comments on commit 0fa812b

Please sign in to comment.