Support COLLATE in expressions

Roughly the <character factor> production - https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#character-factor

If an expression is followed by the keyword `COLLATE`, it must be
followed by the collation name, which is optionally schema-qualified
identifier.

The `COLLATE` keyword is not a regular binary operator in that it can't
be "nested": `foo COLLATE bar COLLATE baz` is not valid. If you prefer
to think of it as an operator, you might say it has the highest
precedence (judging from the spec), i.e. it binds to the smallest valid
expression to the left of it (so in `foo < bar COLLATE c`, the COLLATE
is applied first).
This commit is contained in:
Nickolay Ponomarev 2019-05-04 04:01:47 +03:00
parent e7949d493c
commit f859c9b80e
3 changed files with 29 additions and 1 deletions

View file

@ -209,6 +209,15 @@ fn parse_not() {
//TODO: add assertions
}
#[test]
fn parse_collate() {
let sql = "SELECT name COLLATE \"de_DE\" FROM customer";
assert_matches!(
only(&all_dialects().verified_only_select(sql).projection),
SQLSelectItem::UnnamedExpression(ASTNode::SQLCollate { .. })
);
}
#[test]
fn parse_select_string_predicate() {
let sql = "SELECT id, fname, lname FROM customer \