mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-01 03:37:21 +00:00
Merge pull request #118 from andygrove/outer-join
Don't silently accept naked OUTER JOINS
This commit is contained in:
commit
e6b26330df
3 changed files with 13 additions and 1 deletions
|
@ -422,7 +422,12 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[&str] = &[
|
||||||
// Reserved as both a table and a column alias:
|
// Reserved as both a table and a column alias:
|
||||||
WITH, SELECT, WHERE, GROUP, HAVING, ORDER, LIMIT, OFFSET, FETCH, UNION, EXCEPT, INTERSECT,
|
WITH, SELECT, WHERE, GROUP, HAVING, ORDER, LIMIT, OFFSET, FETCH, UNION, EXCEPT, INTERSECT,
|
||||||
// Reserved only as a table alias in the `FROM`/`JOIN` clauses:
|
// 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`
|
/// Can't be used as a column alias, so that `SELECT <expr> alias`
|
||||||
|
|
|
@ -1648,6 +1648,7 @@ impl Parser {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"OUTER" => return self.expected("LEFT, RIGHT, or FULL", self.peek_token()),
|
||||||
_ if natural => {
|
_ if natural => {
|
||||||
return self.expected("a join type after NATURAL", self.peek_token());
|
return self.expected("a join type after NATURAL", self.peek_token());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1801,6 +1801,12 @@ fn parse_join_syntax_variants() {
|
||||||
"SELECT c1 FROM t1 FULL OUTER JOIN t2 USING(c1)",
|
"SELECT c1 FROM t1 FULL OUTER JOIN t2 USING(c1)",
|
||||||
"SELECT c1 FROM t1 FULL 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]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue