LucaCappelletti94 commented on code in PR #2618:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2618#discussion_r4303186245
##########
src/parser/mod.rs:
##########
@@ -1512,6 +1513,32 @@ impl<'a> Parser<'a> {
Ok(Statement::UNLISTEN { channel })
}
+ /// Parse `DO` statement.
+ pub fn parse_do(&mut self) -> Result<Statement, ParserError> {
+ let mut options = Vec::new();
+ loop {
+ let language = self.parse_keyword(Keyword::LANGUAGE);
+ let string_literal = matches!(
+ self.peek_token_ref().token,
+ Token::SingleQuotedString(_)
+ | Token::DollarQuotedString(_)
+ | Token::EscapedStringLiteral(_)
+ | Token::UnicodeStringLiteral(_)
+ );
+ let option = match (language, string_literal) {
+ (true, true) => DoOption::LanguageLiteral(self.parse_value()?),
+ (true, false) => DoOption::Language(self.parse_identifier()?),
Review Comment:
You should read `LANGUAGE N'...'` the way PostgreSQL does, as the language
`nchar` followed by a code block. PostgreSQL's scanner splits `N'...'` into the
keyword `NCHAR` and a string, and `NCHAR` is a non-reserved word, so `DO
LANGUAGE N'BEGIN NULL; END'` passes `pg_query`. `fuzz_postgres_accepts` panics
on it with `Expected: identifier, found: N'BEGIN NULL; END'`, reached from this
PR's seeds in about two minutes.
```suggestion
(true, false) => match &self.peek_token_ref().token {
// PostgreSQL lexes `N'...'` as the keyword `NCHAR`
followed by a string
Token::NationalStringLiteral(code) => {
let code = Value::SingleQuotedString(code.clone());
let span = self.next_token().span;
options.push(DoOption::Language(Ident::with_span(span, "nchar")));
DoOption::Code(code.with_span(span))
}
_ => DoOption::Language(self.parse_identifier()?),
},
```
--
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]