Skip to content

Commit e6b2633

Browse files
authored
Merge pull request #118 from andygrove/outer-join
Don't silently accept naked OUTER JOINS
2 parents 7857543 + 2c99635 commit e6b2633

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/dialect/keywords.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,12 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[&str] = &[
422422
// Reserved as both a table and a column alias:
423423
WITH, SELECT, WHERE, GROUP, HAVING, ORDER, LIMIT, OFFSET, FETCH, UNION, EXCEPT, INTERSECT,
424424
// Reserved only as a table alias in the `FROM`/`JOIN` clauses:
425-
ON, JOIN, INNER, CROSS, FULL, LEFT, RIGHT, NATURAL, USING,
425+
ON, JOIN, INNER, CROSS, FULL, LEFT, RIGHT, NATURAL, USING, LIMIT, OFFSET, FETCH,
426+
// Reserved not because of ambiguity, but so that parsing `SELECT * FROM a
427+
// OUTER JOIN b` causes a syntax error, rather than silently parsing to an
428+
// inner join where table `a` is aliased as `OUTER`, which is certainly not
429+
// what the user intended and also not valid according to the SQL standard.
430+
OUTER,
426431
];
427432

428433
/// Can't be used as a column alias, so that `SELECT <expr> alias`

src/sqlparser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ impl Parser {
16481648
_ => unreachable!(),
16491649
}
16501650
}
1651+
"OUTER" => return self.expected("LEFT, RIGHT, or FULL", self.peek_token()),
16511652
_ if natural => {
16521653
return self.expected("a join type after NATURAL", self.peek_token());
16531654
}

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,12 @@ fn parse_join_syntax_variants() {
18011801
"SELECT c1 FROM t1 FULL OUTER JOIN t2 USING(c1)",
18021802
"SELECT c1 FROM t1 FULL JOIN t2 USING(c1)",
18031803
);
1804+
1805+
let res = parse_sql_statements("SELECT * FROM a OUTER JOIN b ON 1");
1806+
assert_eq!(
1807+
ParserError::ParserError("Expected LEFT, RIGHT, or FULL, found: OUTER".to_string()),
1808+
res.unwrap_err()
1809+
);
18041810
}
18051811

18061812
#[test]

0 commit comments

Comments
 (0)