Fix parsing of COLLATE after parentheses in expressions (#507)

This commit is contained in:
Riccardo Azzolini 2022-05-25 22:10:38 +02:00 committed by GitHub
parent 901f5b974f
commit 0fa812bd2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View file

@ -525,8 +525,8 @@ impl<'a> Parser<'a> {
}; };
self.expect_token(&Token::RParen)?; self.expect_token(&Token::RParen)?;
if !self.consume_token(&Token::Period) { if !self.consume_token(&Token::Period) {
return Ok(expr); Ok(expr)
} } else {
let tok = self.next_token(); let tok = self.next_token();
let key = match tok { let key = match tok {
Token::Word(word) => word.to_ident(), Token::Word(word) => word.to_ident(),
@ -537,6 +537,7 @@ impl<'a> Parser<'a> {
key, key,
}) })
} }
}
Token::Placeholder(_) => { Token::Placeholder(_) => {
self.prev_token(); self.prev_token();
Ok(Expr::Value(self.parse_value()?)) Ok(Expr::Value(self.parse_value()?))

View file

@ -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] #[test]
fn parse_select_string_predicate() { fn parse_select_string_predicate() {
let sql = "SELECT id, fname, lname FROM customer \ let sql = "SELECT id, fname, lname FROM customer \