LucaCappelletti94 commented on code in PR #2841:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2841#discussion_r4503766058
##########
tests/sqlparser_common.rs:
##########
@@ -23481,3 +23481,62 @@ fn
parse_trailing_end_keyword_is_not_silently_dropped() {
ParserError::ParserError("Expected: end of statement, found:
END".to_string())
);
}
+
+#[test]
+fn parse_create_procedure_string_body() {
+ match verified_stmt("CREATE PROCEDURE p (a INT) LANGUAGE sql AS 'INSERT
INTO t VALUES (a)'") {
+ Statement::CreateProcedure {
+ language,
+ body: CreateProcedureBody::AsString { body, link_symbol },
+ ..
+ } => {
+ assert_eq!(language, Some(Ident::new("sql")));
+ assert_eq!(
+ body,
+ Expr::Value(
+ Value::SingleQuotedString("INSERT INTO t VALUES
(a)".to_string())
+ .with_empty_span()
+ )
+ );
+ assert_eq!(link_symbol, None);
+ }
+ stmt => panic!("unexpected statement: {stmt:?}"),
+ }
+
+ verified_stmt("CREATE PROCEDURE p () LANGUAGE C AS 'MODULE_PATHNAME',
'p_wrapper'");
+ one_statement_parses_to(
+ "CREATE PROCEDURE p () AS 'SELECT 1' LANGUAGE sql",
+ "CREATE PROCEDURE p () LANGUAGE sql AS 'SELECT 1'",
+ );
+
+ pg_and_generic().verified_stmt(
+ "CREATE PROCEDURE p (a INT) LANGUAGE plpgsql AS $$ BEGIN INSERT INTO t
VALUES (a); END; $$",
+ );
+ pg_and_generic().verified_stmt("CREATE PROCEDURE p () LANGUAGE sql AS
$body$ SELECT 1 $body$");
Review Comment:
You could cover the escape string body, which fails without the change above.
```suggestion
pg_and_generic().verified_stmt("CREATE PROCEDURE p () LANGUAGE sql AS
$body$ SELECT 1 $body$");
pg_and_generic().one_statement_parses_to(
"CREATE PROCEDURE p () LANGUAGE sql AS E'SELECT 1'",
"CREATE PROCEDURE p () LANGUAGE sql AS 'SELECT 1'",
);
```
##########
src/parser/mod.rs:
##########
@@ -21985,7 +21991,18 @@ impl<'a> Parser<'a> {
Some(statements) => CreateProcedureBody::BeginAtomic(statements),
None => {
self.expect_keyword_is(Keyword::AS)?;
-
CreateProcedureBody::As(self.parse_conditional_statements(&[Keyword::END])?)
+ if matches!(
+ self.peek_token_ref().token,
+ Token::SingleQuotedString(_) | Token::DollarQuotedString(_)
Review Comment:
You should let the other string constants through here too.
`parse_definition_string` already reads `E'...'` and `U&'...'`, but this check
sends them to the statement path, so `CREATE PROCEDURE p () LANGUAGE sql AS
E'SELECT 1'` fails with `Expected: an SQL statement, found: E'SELECT 1'` while
PostgreSQL 18 creates and calls that procedure.
```suggestion
Token::SingleQuotedString(_)
| Token::DollarQuotedString(_)
| Token::EscapedStringLiteral(_)
| Token::UnicodeStringLiteral(_)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]