Skip to content

Commit a16791d

Browse files
authored
Support UNNEST as a table factor for PostgreSQL (#968)
1 parent 0480ee9 commit a16791d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6240,7 +6240,7 @@ impl<'a> Parser<'a> {
62406240
// appearing alone in parentheses (e.g. `FROM (mytable)`)
62416241
self.expected("joined table", self.peek_token())
62426242
}
6243-
} else if dialect_of!(self is BigQueryDialect | GenericDialect)
6243+
} else if dialect_of!(self is BigQueryDialect | PostgreSqlDialect | GenericDialect)
62446244
&& self.parse_keyword(Keyword::UNNEST)
62456245
{
62466246
self.expect_token(&Token::LParen)?;

tests/sqlparser_postgres.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,3 +3450,30 @@ fn parse_create_table_with_alias() {
34503450
_ => unreachable!(),
34513451
}
34523452
}
3453+
3454+
#[test]
3455+
fn parse_join_constraint_unnest_alias() {
3456+
assert_eq!(
3457+
only(
3458+
pg().verified_only_select("SELECT * FROM t1 JOIN UNNEST(t1.a) AS f ON c1 = c2")
3459+
.from
3460+
)
3461+
.joins,
3462+
vec![Join {
3463+
relation: TableFactor::UNNEST {
3464+
alias: table_alias("f"),
3465+
array_exprs: vec![Expr::CompoundIdentifier(vec![
3466+
Ident::new("t1"),
3467+
Ident::new("a")
3468+
])],
3469+
with_offset: false,
3470+
with_offset_alias: None
3471+
},
3472+
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
3473+
left: Box::new(Expr::Identifier("c1".into())),
3474+
op: BinaryOperator::Eq,
3475+
right: Box::new(Expr::Identifier("c2".into())),
3476+
})),
3477+
}]
3478+
);
3479+
}

0 commit comments

Comments
 (0)