Support table aliases without AS (7/8)

...as in `FROM foo bar WHERE bar.x > 1`.

To avoid ambiguity as to whether a token is an alias or a keyword, we
maintain a blacklist of keywords, that can follow a "table factor", to
prevent parsing them as an alias. This "context-specific reserved
keyword" approach lets us accept more SQL that's valid in some dialects,
than a list of globally reserved keywords. Also some dialects (e.g.
Oracle) apparently don't reserve some keywords (like JOIN), while
presumably they won't accept them as an alias (`FROM foo JOIN` meaning
`FROM foo AS JOIN`).
This commit is contained in:
Nickolay Ponomarev 2019-01-21 01:28:59 +03:00
parent 536fa6e428
commit 76ec175d20
3 changed files with 36 additions and 11 deletions

View file

@ -601,6 +601,10 @@ fn parse_joins_on() {
JoinOperator::Inner
)]
);
parses_to(
"SELECT * FROM t1 JOIN t2 foo ON c1 = c2",
"SELECT * FROM t1 JOIN t2 AS foo ON c1 = c2",
);
// Test parsing of different join operators
assert_eq!(
joins_from(verified("SELECT * FROM t1 JOIN t2 ON c1 = c2")),
@ -644,6 +648,10 @@ fn parse_joins_using() {
JoinOperator::Inner
)]
);
parses_to(
"SELECT * FROM t1 JOIN t2 foo USING(c1)",
"SELECT * FROM t1 JOIN t2 AS foo USING(c1)",
);
// Test parsing of different join operators
assert_eq!(
joins_from(verified("SELECT * FROM t1 JOIN t2 USING(c1)")),