Merge pull request #118 from andygrove/outer-join

Don't silently accept naked OUTER JOINS
This commit is contained in:
Nikhil Benesch 2019-06-18 13:15:25 -04:00 committed by GitHub
commit e6b26330df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View file

@ -422,7 +422,12 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[&str] = &[
// Reserved as both a table and a column alias:
WITH, SELECT, WHERE, GROUP, HAVING, ORDER, LIMIT, OFFSET, FETCH, UNION, EXCEPT, INTERSECT,
// Reserved only as a table alias in the `FROM`/`JOIN` clauses:
ON, JOIN, INNER, CROSS, FULL, LEFT, RIGHT, NATURAL, USING,
ON, JOIN, INNER, CROSS, FULL, LEFT, RIGHT, NATURAL, USING, LIMIT, OFFSET, FETCH,
// Reserved not because of ambiguity, but so that parsing `SELECT * FROM a
// OUTER JOIN b` causes a syntax error, rather than silently parsing to an
// inner join where table `a` is aliased as `OUTER`, which is certainly not
// what the user intended and also not valid according to the SQL standard.
OUTER,
];
/// Can't be used as a column alias, so that `SELECT <expr> alias`

View file

@ -1648,6 +1648,7 @@ impl Parser {
_ => unreachable!(),
}
}
"OUTER" => return self.expected("LEFT, RIGHT, or FULL", self.peek_token()),
_ if natural => {
return self.expected("a join type after NATURAL", self.peek_token());
}

View file

@ -1801,6 +1801,12 @@ fn parse_join_syntax_variants() {
"SELECT c1 FROM t1 FULL OUTER JOIN t2 USING(c1)",
"SELECT c1 FROM t1 FULL JOIN t2 USING(c1)",
);
let res = parse_sql_statements("SELECT * FROM a OUTER JOIN b ON 1");
assert_eq!(
ParserError::ParserError("Expected LEFT, RIGHT, or FULL, found: OUTER".to_string()),
res.unwrap_err()
);
}
#[test]