Skip to content

Commit 57b510a

Browse files
committed
Allow no joins only for TableFactor::NestedJoin
...instead of listing all the table factor variants that must be followed by joins when parenthesized. This way is closer to the spec -- see `<parenthesized joined table>` definition https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#parenthesized-joined-table
1 parent 287f755 commit 57b510a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/sqlast/query.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ pub enum TableFactor {
226226
subquery: Box<SQLQuery>,
227227
alias: Option<TableAlias>,
228228
},
229+
/// Represents a parenthesized join expression, such as
230+
/// `(foo <JOIN> bar [ <JOIN> baz ... ])`.
231+
/// The inner `TableWithJoins` can have no joins only if its
232+
/// `relation` is itself a `TableFactor::NestedJoin`.
229233
NestedJoin(Box<TableWithJoins>),
230234
}
231235

src/sqlparser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,14 +1712,14 @@ impl Parser {
17121712
self.index = index;
17131713
let table_and_joins = self.parse_table_and_joins()?;
17141714
match table_and_joins.relation {
1715-
TableFactor::Table { .. } | TableFactor::Derived { .. }
1716-
if table_and_joins.joins.is_empty() =>
1717-
{
1718-
// The SQL spec prohibits derived tables and bare
1719-
// tables from appearing alone in parentheses.
1720-
self.expected("joined table", self.peek_token())?
1715+
TableFactor::NestedJoin { .. } => (),
1716+
_ => {
1717+
if table_and_joins.joins.is_empty() {
1718+
// The SQL spec prohibits derived tables and bare
1719+
// tables from appearing alone in parentheses.
1720+
self.expected("joined table", self.peek_token())?
1721+
}
17211722
}
1722-
_ => (),
17231723
}
17241724
self.expect_token(&Token::RParen)?;
17251725
Ok(TableFactor::NestedJoin(Box::new(table_and_joins)))

0 commit comments

Comments
 (0)