@@ -1771,7 +1771,6 @@ impl Parser {
1771
1771
// ^ ^ ^ ^
1772
1772
// | | | |
1773
1773
// | | | |
1774
- // | | | |
1775
1774
// | | | (4) belongs to a SetExpr::Query inside the subquery
1776
1775
// | | (3) starts a derived table (subquery)
1777
1776
// | (2) starts a nested join
@@ -1784,23 +1783,20 @@ impl Parser {
1784
1783
// case (3), and the next token would be `NATURAL`.
1785
1784
Ok ( table_factor) => Ok ( table_factor) ,
1786
1785
Err ( _) => {
1787
- // The '(' we've recently consumed does not start a derived
1788
- // table. For valid input this can happen either when the
1789
- // token following the paren can't start a query (e.g. `foo`
1790
- // in `FROM (foo NATURAL JOIN bar)`, or when the '(' we've
1791
- // consumed is followed by another '(' that starts a
1792
- // derived table, like (3), or another nested join (2).
1793
- //
1794
- // Ignore the error and back up to where we were before.
1795
- // Either we'll be able to parse a valid nested join, or
1796
- // we won't, and we'll return that error instead.
1797
- //
1798
- // Even the SQL spec prohibits derived tables and bare
1799
- // tables from appearing alone in parentheses, we allowed it
1800
- // as some Db's allowed that (snowflake as example)
1786
+ // A parsing error from `parse_derived_table_factor` indicates that
1787
+ // the '(' we've recently consumed does not start a derived table
1788
+ // (cases 1, 2, or 4). Ignore the error and back up to where we
1789
+ // were before - right after the opening '('.
1801
1790
self . index = index;
1791
+
1792
+ // Inside the parentheses we expect to find a table factor
1793
+ // followed by some joins or another level of nesting.
1802
1794
let table_and_joins = self . parse_table_and_joins ( ) ?;
1803
1795
self . expect_token ( & Token :: RParen ) ?;
1796
+ // The SQL spec prohibits derived and bare tables from appearing
1797
+ // alone in parentheses. We don't enforce this as some databases
1798
+ // (e.g. Snowflake) allow such syntax.
1799
+
1804
1800
Ok ( TableFactor :: NestedJoin ( Box :: new ( table_and_joins) ) )
1805
1801
}
1806
1802
}
0 commit comments