@@ -3242,6 +3242,7 @@ impl<'a> Parser<'a> {
3242
3242
} else {
3243
3243
vec ! [ ]
3244
3244
} ;
3245
+
3245
3246
let mut lateral_views = vec ! [ ] ;
3246
3247
loop {
3247
3248
if self . parse_keywords ( & [ Keyword :: LATERAL , Keyword :: VIEW ] ) {
@@ -3490,7 +3491,6 @@ impl<'a> Parser<'a> {
3490
3491
3491
3492
pub fn parse_table_and_joins ( & mut self ) -> Result < TableWithJoins , ParserError > {
3492
3493
let relation = self . parse_table_factor ( ) ?;
3493
-
3494
3494
// Note that for keywords to be properly handled here, they need to be
3495
3495
// added to `RESERVED_FOR_TABLE_ALIAS`, otherwise they may be parsed as
3496
3496
// a table alias.
@@ -3635,6 +3635,7 @@ impl<'a> Parser<'a> {
3635
3635
match & mut table_and_joins. relation {
3636
3636
TableFactor :: Derived { alias, .. }
3637
3637
| TableFactor :: Table { alias, .. }
3638
+ | TableFactor :: UNNEST { alias, .. }
3638
3639
| TableFactor :: TableFunction { alias, .. } => {
3639
3640
// but not `FROM (mytable AS alias1) AS alias2`.
3640
3641
if let Some ( inner_alias) = alias {
@@ -3658,6 +3659,29 @@ impl<'a> Parser<'a> {
3658
3659
// appearing alone in parentheses (e.g. `FROM (mytable)`)
3659
3660
self . expected ( "joined table" , self . peek_token ( ) )
3660
3661
}
3662
+ } else if dialect_of ! ( self is BigQueryDialect | GenericDialect )
3663
+ && self . parse_keyword ( Keyword :: UNNEST )
3664
+ {
3665
+ self . expect_token ( & Token :: LParen ) ?;
3666
+ let expr = self . parse_expr ( ) ?;
3667
+ self . expect_token ( & Token :: RParen ) ?;
3668
+
3669
+ let alias = match self . parse_optional_table_alias ( keywords:: RESERVED_FOR_TABLE_ALIAS ) {
3670
+ Ok ( Some ( alias) ) => Some ( alias) ,
3671
+ Ok ( None ) => None ,
3672
+ Err ( e) => return Err ( e) ,
3673
+ } ;
3674
+
3675
+ let with_offset = match self . expect_keywords ( & [ Keyword :: WITH , Keyword :: OFFSET ] ) {
3676
+ Ok ( ( ) ) => true ,
3677
+ Err ( _) => false ,
3678
+ } ;
3679
+
3680
+ Ok ( TableFactor :: UNNEST {
3681
+ alias,
3682
+ array_expr : Box :: new ( expr) ,
3683
+ with_offset,
3684
+ } )
3661
3685
} else {
3662
3686
let name = self . parse_object_name ( ) ?;
3663
3687
// Postgres, MSSQL: table-valued functions:
0 commit comments