-
Notifications
You must be signed in to change notification settings - Fork 711
Add SETOF support for PostgreSQL function return types #2217
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
Changes from 3 commits
bd9e0a9
4954465
eb495f2
4094fc8
17910f2
b31d30c
11a37c6
e5a0958
a516fec
e9a35be
187eae9
20d842f
b639e4d
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 |
|---|---|---|
|
|
@@ -597,6 +597,31 @@ impl Spanned for CreateTable { | |
| } | ||
| } | ||
|
|
||
| impl Spanned for PartitionBoundValue { | ||
| fn span(&self) -> Span { | ||
| match self { | ||
| PartitionBoundValue::Expr(expr) => expr.span(), | ||
| PartitionBoundValue::MinValue => Span::empty(), | ||
| PartitionBoundValue::MaxValue => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for ForValues { | ||
| fn span(&self) -> Span { | ||
| match self { | ||
| ForValues::In(exprs) => union_spans(exprs.iter().map(|e| e.span())), | ||
| ForValues::From { from, to } => union_spans( | ||
| from.iter() | ||
| .map(|v| v.span()) | ||
| .chain(to.iter().map(|v| v.span())), | ||
| ), | ||
| ForValues::With { .. } => Span::empty(), | ||
| ForValues::Default => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for ColumnDef { | ||
| fn span(&self) -> Span { | ||
| let ColumnDef { | ||
|
|
@@ -632,33 +657,6 @@ impl Spanned for TableConstraint { | |
| } | ||
| } | ||
|
|
||
| impl Spanned for PartitionBoundValue { | ||
|
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. is there any changes in this diff (if not can we revert it)?
Contributor
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. |
||
| fn span(&self) -> Span { | ||
| match self { | ||
| PartitionBoundValue::Expr(expr) => expr.span(), | ||
| // MINVALUE and MAXVALUE are keywords without tracked spans | ||
| PartitionBoundValue::MinValue => Span::empty(), | ||
| PartitionBoundValue::MaxValue => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for ForValues { | ||
| fn span(&self) -> Span { | ||
| match self { | ||
| ForValues::In(exprs) => union_spans(exprs.iter().map(|e| e.span())), | ||
| ForValues::From { from, to } => union_spans( | ||
| from.iter() | ||
| .map(|v| v.span()) | ||
| .chain(to.iter().map(|v| v.span())), | ||
| ), | ||
| // WITH (MODULUS n, REMAINDER r) - u64 values have no spans | ||
| ForValues::With { .. } => Span::empty(), | ||
| ForValues::Default => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for CreateIndex { | ||
| fn span(&self) -> Span { | ||
| let CreateIndex { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -933,6 +933,7 @@ define_keywords!( | |
| SESSION_USER, | ||
| SET, | ||
| SETERROR, | ||
| SETOF, | ||
| SETS, | ||
| SETTINGS, | ||
| SHARE, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5545,7 +5545,7 @@ impl<'a> Parser<'a> { | |||||
| self.expect_token(&Token::RParen)?; | ||||||
|
|
||||||
| let return_type = if self.parse_keyword(Keyword::RETURNS) { | ||||||
| Some(self.parse_data_type()?) | ||||||
| Some(self.parse_function_return_type()?) | ||||||
| } else { | ||||||
| None | ||||||
| }; | ||||||
|
|
@@ -5724,7 +5724,7 @@ impl<'a> Parser<'a> { | |||||
| let (name, args) = self.parse_create_function_name_and_params()?; | ||||||
|
|
||||||
| let return_type = if self.parse_keyword(Keyword::RETURNS) { | ||||||
| Some(self.parse_data_type()?) | ||||||
| Some(self.parse_function_return_type()?) | ||||||
| } else { | ||||||
| None | ||||||
| }; | ||||||
|
|
@@ -5827,11 +5827,11 @@ impl<'a> Parser<'a> { | |||||
| }) | ||||||
| })?; | ||||||
|
|
||||||
| let return_type = if return_table.is_some() { | ||||||
| return_table | ||||||
| } else { | ||||||
| Some(self.parse_data_type()?) | ||||||
| let data_type = match return_table { | ||||||
| Some(table_type) => table_type, | ||||||
| None => self.parse_data_type()?, | ||||||
| }; | ||||||
| let return_type = Some(FunctionReturnType::DataType(data_type)); | ||||||
|
|
||||||
| let _ = self.parse_keyword(Keyword::AS); | ||||||
|
|
||||||
|
|
@@ -5883,6 +5883,17 @@ impl<'a> Parser<'a> { | |||||
| }) | ||||||
| } | ||||||
|
|
||||||
| /// Parse a [`FunctionReturnType`] after the `RETURNS` keyword. | ||||||
| /// | ||||||
| /// Handles `RETURNS SETOF <type>` and plain `RETURNS <type>`. | ||||||
|
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.
Suggested change
Contributor
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. |
||||||
| fn parse_function_return_type(&mut self) -> Result<FunctionReturnType, ParserError> { | ||||||
| if self.parse_keyword(Keyword::SETOF) { | ||||||
| Ok(FunctionReturnType::SetOf(self.parse_data_type()?)) | ||||||
| } else { | ||||||
| Ok(FunctionReturnType::DataType(self.parse_data_type()?)) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| fn parse_create_function_name_and_params( | ||||||
| &mut self, | ||||||
| ) -> Result<(ObjectName, Vec<OperateFunctionArg>), ParserError> { | ||||||
|
|
||||||
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 instead move the link to the postgres docs here? since the enum itself applies to all dialects, whereas only this variant is pg specific
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.
e9a35be