LucaCappelletti94 commented on code in PR #2618:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2618#discussion_r4273971869
##########
src/parser/mod.rs:
##########
@@ -1512,6 +1513,30 @@ impl<'a> Parser<'a> {
Ok(Statement::UNLISTEN { channel })
}
+ /// Parse `DO` statement.
+ pub fn parse_do(&mut self) -> Result<Statement, ParserError> {
+ let mut language = self.parse_do_language()?;
+ match &self.peek_token_ref().token {
+ Token::SingleQuotedString(_)
+ | Token::DollarQuotedString(_)
+ | Token::EscapedStringLiteral(_) => {}
Review Comment:
You should accept the Unicode escape string as a code block too. PostgreSQL
18 runs `DO U&'BEGIN NULL; END'`, and the PostgreSQL dialect tokenizes it as
`Token::UnicodeStringLiteral`, so this match rejects it with `Expected: string
literal, found: U&'BEGIN NULL; END'`.
```suggestion
| Token::EscapedStringLiteral(_)
| Token::UnicodeStringLiteral(_) => {}
```
##########
tests/sqlparser_common.rs:
##########
@@ -20511,3 +20511,58 @@ fn
parse_position_in_connect_by_list_after_state_change() {
assert_eq!(positions, 1, "{dialect:?}");
}
}
+
+#[test]
+fn parse_do_statement() {
+ let dialects = all_dialects_where(|d| d.supports_do_statement());
+
+ match dialects.verified_stmt("DO $$BEGIN RAISE NOTICE 'hi'; END$$") {
+ Statement::Do(DoStatement { language, code }) => {
+ assert_eq!(language, None);
+ assert_eq!(
+ code.value,
+ Value::DollarQuotedString(DollarQuotedString {
+ value: "BEGIN RAISE NOTICE 'hi'; END".to_string(),
+ tag: None,
+ })
+ );
+ }
+ _ => unreachable!(),
+ }
+
+ match dialects.verified_stmt("DO LANGUAGE plpgsql $body$BEGIN NULL;
END$body$") {
+ Statement::Do(DoStatement { language, .. }) => {
+ assert_eq!(language, Some(Ident::new("plpgsql")));
+ }
+ _ => unreachable!(),
+ }
+
+ dialects.verified_stmt("DO 'BEGIN NULL; END'");
Review Comment:
And its red test.
```suggestion
dialects.verified_stmt("DO 'BEGIN NULL; END'");
dialects.verified_stmt("DO U&'BEGIN NULL; END'");
```
--
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]