iffyio commented on code in PR #1826:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1826#discussion_r2067143571


##########
src/parser/mod.rs:
##########
@@ -5199,12 +5199,22 @@ impl<'a> Parser<'a> {
 
         // parse: [ argname ] argtype
         let mut name = None;
+        let next_token = self.peek_token();
         let mut data_type = self.parse_data_type()?;
-        if let DataType::Custom(n, _) = &data_type {
-            // the first token is actually a name
-            match n.0[0].clone() {
-                ObjectNamePart::Identifier(ident) => name = Some(ident),
-            }
+
+        // It may appear that the first token can be converted into a known
+        // type, but this could also be a collision as some types are only
+        // present in some dialects and therefore some type reserved keywords
+        // may be freely used as argument names in other dialects.
+
+        // To check whether the first token is a name or a type, we need to
+        // peek the next token, which if it is another type keyword, then the
+        // first token is a name and not a type in itself.
+        let potential_tokens = [Token::Eq, Token::RParen, Token::Comma];
+        if !self.peek_keyword(Keyword::DEFAULT)
+            && !potential_tokens.contains(&self.peek_token().token)
+        {
+            name = Some(Ident::new(next_token.to_string()));

Review Comment:
   wondering if something like this work instead?
   ```rust
   if let DataType::Custom(n, _) = &data_type {
     if let Some(dt) = self.maybe_parse(|parser| parser.parse_data_type())? {
       match n.0[0].clone() {
         ObjectNamePart::Identifier(ident) => name = Some(ident),
       }
       data_type = dt;
     }
   }
   ```
   thinking if so it would closer match the desired goal to parse an optional 
datatype if the first token is regular 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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to