File tree 3 files changed +27
-1
lines changed
3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -238,6 +238,10 @@ pub enum TableFactor {
238
238
subquery : Box < SQLQuery > ,
239
239
alias : Option < TableAlias > ,
240
240
} ,
241
+ /// Represents a parenthesized join expression, such as
242
+ /// `(foo <JOIN> bar [ <JOIN> baz ... ])`.
243
+ /// The inner `TableWithJoins` can have no joins only if its
244
+ /// `relation` is itself a `TableFactor::NestedJoin`.
241
245
NestedJoin ( Box < TableWithJoins > ) ,
242
246
}
243
247
Original file line number Diff line number Diff line change @@ -1719,6 +1719,16 @@ impl Parser {
1719
1719
// we won't, and we'll return that error instead.
1720
1720
self . index = index;
1721
1721
let table_and_joins = self . parse_table_and_joins ( ) ?;
1722
+ match table_and_joins. relation {
1723
+ TableFactor :: NestedJoin { .. } => ( ) ,
1724
+ _ => {
1725
+ if table_and_joins. joins . is_empty ( ) {
1726
+ // The SQL spec prohibits derived tables and bare
1727
+ // tables from appearing alone in parentheses.
1728
+ self . expected ( "joined table" , self . peek_token ( ) ) ?
1729
+ }
1730
+ }
1731
+ }
1722
1732
self . expect_token ( & Token :: RParen ) ?;
1723
1733
Ok ( TableFactor :: NestedJoin ( Box :: new ( table_and_joins) ) )
1724
1734
}
Original file line number Diff line number Diff line change @@ -1742,6 +1742,12 @@ fn parse_join_nesting() {
1742
1742
from. joins,
1743
1743
vec![ join( nest!( nest!( nest!( table( "b" ) , table( "c" ) ) ) ) ) ]
1744
1744
) ;
1745
+
1746
+ let res = parse_sql_statements ( "SELECT * FROM (a NATURAL JOIN (b))" ) ;
1747
+ assert_eq ! (
1748
+ ParserError :: ParserError ( "Expected joined table, found: )" . to_string( ) ) ,
1749
+ res. unwrap_err( )
1750
+ ) ;
1745
1751
}
1746
1752
1747
1753
#[ test]
@@ -1873,7 +1879,13 @@ fn parse_derived_tables() {
1873
1879
join_operator: JoinOperator :: Inner ( JoinConstraint :: Natural ) ,
1874
1880
} ] ,
1875
1881
} ) )
1876
- )
1882
+ ) ;
1883
+
1884
+ let res = parse_sql_statements ( "SELECT * FROM ((SELECT 1) AS t)" ) ;
1885
+ assert_eq ! (
1886
+ ParserError :: ParserError ( "Expected joined table, found: )" . to_string( ) ) ,
1887
+ res. unwrap_err( )
1888
+ ) ;
1877
1889
}
1878
1890
1879
1891
#[ test]
You can’t perform that action at this time.
0 commit comments