caldwell commented on code in PR #1460:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1460#discussion_r1807938582


##########
src/dialect/postgresql.rs:
##########
@@ -138,6 +138,14 @@ impl Dialect for PostgreSqlDialect {
     fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, 
ParserError>> {
         if parser.parse_keyword(Keyword::COMMENT) {
             Some(parse_comment(parser))
+        } else if parser.parse_keyword(Keyword::CREATE) {
+            match parse_create(parser) {
+                Some(result) => Some(result),
+                None => {
+                    parser.prev_token(); // unconsume the CREATE if we didn't 
end up parsing anything
+                    None
+                }

Review Comment:
   Yes, that can make it much simpler. I also tried using peek to avoid doing 
"consume, unconsume, consume" but it looks like there's no nice 
`peek_keyword()` type function and so it ended up looking like:
   ```rust
   if matches!(parser.peek_token().token, Token::Word(Word { keyword: 
Keyword::CREATE, .. })) {
       parse_create(parser)
   }
   ```
   That's a bit of a mouthful and I ended up just going with your suggestion:
   ```rust
   if parser.parse_keyword(Keyword::CREATE) {
       parser.prev_token(); // unconsume the CREATE in case we don't end up 
parsing anything
       parse_create(parser)
   }
   ```



-- 
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]

Reply via email to