@@ -11712,6 +11712,11 @@ impl<'a> Parser<'a> {
11712
11712
// Note that for keywords to be properly handled here, they need to be
11713
11713
// added to `RESERVED_FOR_TABLE_ALIAS`, otherwise they may be parsed as
11714
11714
// a table alias.
11715
+ let joins = self.parse_joins()?;
11716
+ Ok(TableWithJoins { relation, joins })
11717
+ }
11718
+
11719
+ fn parse_joins(&mut self) -> Result<Vec<Join>, ParserError> {
11715
11720
let mut joins = vec![];
11716
11721
loop {
11717
11722
let global = self.parse_keyword(Keyword::GLOBAL);
@@ -11844,7 +11849,16 @@ impl<'a> Parser<'a> {
11844
11849
}
11845
11850
_ => break,
11846
11851
};
11847
- let relation = self.parse_table_factor()?;
11852
+ let mut relation = self.parse_table_factor()?;
11853
+
11854
+ if self.peek_parens_less_nested_join() {
11855
+ let joins = self.parse_joins()?;
11856
+ relation = TableFactor::NestedJoin {
11857
+ table_with_joins: Box::new(TableWithJoins { relation, joins }),
11858
+ alias: None,
11859
+ };
11860
+ }
11861
+
11848
11862
let join_constraint = self.parse_join_constraint(natural)?;
11849
11863
Join {
11850
11864
relation,
@@ -11854,7 +11868,21 @@ impl<'a> Parser<'a> {
11854
11868
};
11855
11869
joins.push(join);
11856
11870
}
11857
- Ok(TableWithJoins { relation, joins })
11871
+ Ok(joins)
11872
+ }
11873
+
11874
+ fn peek_parens_less_nested_join(&self) -> bool {
11875
+ matches!(
11876
+ self.peek_token_ref().token,
11877
+ Token::Word(Word {
11878
+ keyword: Keyword::JOIN
11879
+ | Keyword::INNER
11880
+ | Keyword::LEFT
11881
+ | Keyword::RIGHT
11882
+ | Keyword::FULL,
11883
+ ..
11884
+ })
11885
+ )
11858
11886
}
11859
11887
11860
11888
/// A table name or a parenthesized subquery, followed by optional `[AS] alias`
0 commit comments