-
Notifications
You must be signed in to change notification settings - Fork 669
Support PostgreSQL C Functions with Multiple AS Parameters #2095
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 3 commits
d173e82
b2acc60
886ac09
e856d89
36b3e66
716efdc
848e117
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 |
|---|---|---|
|
|
@@ -10224,17 +10224,32 @@ impl<'a> Parser<'a> { | |
| /// Parse the body of a `CREATE FUNCTION` specified as a string. | ||
| /// e.g. `CREATE FUNCTION ... AS $$ body $$`. | ||
| fn parse_create_function_body_string(&mut self) -> Result<Expr, ParserError> { | ||
| let peek_token = self.peek_token(); | ||
| let span = peek_token.span; | ||
| match peek_token.token { | ||
| Token::DollarQuotedString(s) if dialect_of!(self is PostgreSqlDialect | GenericDialect) => | ||
| { | ||
| self.next_token(); | ||
| Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span))) | ||
| // Helper closure to parse a single string value (quoted or dollar-quoted) | ||
| let parse_string_expr = |parser: &mut Parser| -> Result<Expr, ParserError> { | ||
| let peek_token = parser.peek_token(); | ||
| let span = peek_token.span; | ||
| match peek_token.token { | ||
| Token::DollarQuotedString(s) if dialect_of!(parser is PostgreSqlDialect | GenericDialect) => | ||
| { | ||
| parser.next_token(); | ||
| Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span))) | ||
| } | ||
| _ => Ok(Expr::Value( | ||
| Value::SingleQuotedString(parser.parse_literal_string()?).with_span(span), | ||
| )), | ||
| } | ||
| _ => Ok(Expr::Value( | ||
| Value::SingleQuotedString(self.parse_literal_string()?).with_span(span), | ||
| )), | ||
| }; | ||
|
|
||
| let first_expr = parse_string_expr(self)?; | ||
|
|
||
| // Check if there's a comma, indicating multiple strings (e.g., AS 'obj_file', 'link_symbol') | ||
| // This is used for C language functions: AS 'MODULE_PATHNAME', 'link_symbol' | ||
| if self.consume_token(&Token::Comma) { | ||
| let mut exprs = vec![first_expr]; | ||
| exprs.extend(self.parse_comma_separated(parse_string_expr)?); | ||
| Ok(Expr::Tuple(exprs)) | ||
|
Comment on lines
+10262
to
+10264
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. oh, does wrapping this in a Tuple not include a parenthesis
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. Ah simply the following happens: if let Some(CreateFunctionBody::AsBeforeOptions(function_body)) = &self.function_body {
write!(f, " AS ")?;
// Special handling for tuple expressions to format without parentheses
// PostgreSQL C functions use: AS 'obj_file', 'link_symbol'
// rather than: AS ('obj_file', 'link_symbol')
if let Expr::Tuple(exprs) = function_body {
write!(f, "{}", display_comma_separated(exprs))?;
} else {
write!(f, "{function_body}")?;
}
} |
||
| } else { | ||
| Ok(first_expr) | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.