-
Notifications
You must be signed in to change notification settings - Fork 744
Added support for unpivot in Redshift with expression and bracketsless #2375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
777243f
9411459
81c7308
72b7d32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16494,6 +16494,12 @@ impl<'a> Parser<'a> { | |
| // `(mytable AS alias)` | ||
| alias.replace(outer_alias); | ||
| } | ||
| TableFactor::UnpivotExpr { .. } => { | ||
| return Err(ParserError::ParserError( | ||
| "alias after parenthesized UNPIVOT expression is not supported" | ||
| .to_string(), | ||
| )) | ||
| } | ||
| }; | ||
| } | ||
| // Do not store the extra set of parens in the AST | ||
|
|
@@ -16575,6 +16581,10 @@ impl<'a> Parser<'a> { | |
| with_offset_alias, | ||
| with_ordinality, | ||
| }) | ||
| } else if self.dialect.supports_unpivot_expr() | ||
| && self.parse_keyword(Keyword::UNPIVOT) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we change this to
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you plwase explain it? |
||
| { | ||
| self.parse_unpivot_expr_table_factor() | ||
| } else if self.parse_keyword_with_tokens(Keyword::JSON_TABLE, &[Token::LParen]) { | ||
| let json_expr = self.parse_expr()?; | ||
| self.expect_token(&Token::Comma)?; | ||
|
|
@@ -17573,6 +17583,27 @@ impl<'a> Parser<'a> { | |
| }) | ||
| } | ||
|
|
||
| /// Parse an object UNPIVOT table factor in FROM clause. | ||
| /// | ||
| /// Syntax: | ||
| /// `UNPIVOT expression AS value_alias [AT attribute_alias]` | ||
| pub fn parse_unpivot_expr_table_factor(&mut self) -> Result<TableFactor, ParserError> { | ||
| let expression = self.parse_expr()?; | ||
| self.expect_keyword_is(Keyword::AS)?; | ||
| let value_alias = self.parse_identifier()?; | ||
| let attribute_alias = if self.parse_keyword(Keyword::AT) { | ||
| Some(self.parse_identifier()?) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| Ok(TableFactor::UnpivotExpr { | ||
| expression, | ||
| value_alias, | ||
| attribute_alias, | ||
| }) | ||
| } | ||
|
|
||
| /// Parse a JOIN constraint (`NATURAL`, `ON <expr>`, `USING (...)`, or no constraint). | ||
| pub fn parse_join_constraint(&mut self, natural: bool) -> Result<JoinConstraint, ParserError> { | ||
| if natural { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a link to the docs describing the syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added link to docs