@@ -11712,6 +11712,11 @@ impl<'a> Parser<'a> {
1171211712 // Note that for keywords to be properly handled here, they need to be
1171311713 // added to `RESERVED_FOR_TABLE_ALIAS`, otherwise they may be parsed as
1171411714 // 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> {
1171511720 let mut joins = vec![];
1171611721 loop {
1171711722 let global = self.parse_keyword(Keyword::GLOBAL);
@@ -11844,7 +11849,16 @@ impl<'a> Parser<'a> {
1184411849 }
1184511850 _ => break,
1184611851 };
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+
1184811862 let join_constraint = self.parse_join_constraint(natural)?;
1184911863 Join {
1185011864 relation,
@@ -11854,7 +11868,21 @@ impl<'a> Parser<'a> {
1185411868 };
1185511869 joins.push(join);
1185611870 }
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+ )
1185811886 }
1185911887
1186011888 /// A table name or a parenthesized subquery, followed by optional `[AS] alias`
0 commit comments