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


##########
tests/sqlparser_mysql.rs:
##########
@@ -3457,6 +3457,13 @@ fn parse_create_table_unallow_constraint_then_index() {
     assert!(mysql_and_generic().parse_sql_statements(sql).is_ok());
 }
 
+#[test]
+fn parse_create_table_constraint_check_without_name() {
+    let sql = "CREATE TABLE t (x INT, CONSTRAINT CHECK (x > 1))";

Review Comment:
   can we also add cases for primary/unique/foreign ?



##########
src/parser/mod.rs:
##########
@@ -9252,7 +9252,16 @@ impl<'a> Parser<'a> {
         &mut self,
     ) -> Result<Option<TableConstraint>, ParserError> {
         let name = if self.parse_keyword(Keyword::CONSTRAINT) {
-            Some(self.parse_identifier()?)
+            if self.dialect.supports_constraint_keyword_without_name()
+                && (self.peek_keyword(Keyword::CHECK)
+                    || self.peek_keyword(Keyword::PRIMARY)
+                    || self.peek_keyword(Keyword::UNIQUE)
+                    || self.peek_keyword(Keyword::FOREIGN))

Review Comment:
   can we use `self.peek_one_of_keywords()` here?



##########
tests/sqlparser_mysql.rs:
##########
@@ -3457,6 +3457,13 @@ fn parse_create_table_unallow_constraint_then_index() {
     assert!(mysql_and_generic().parse_sql_statements(sql).is_ok());
 }
 
+#[test]
+fn parse_create_table_constraint_check_without_name() {
+    let sql = "CREATE TABLE t (x INT, CONSTRAINT CHECK (x > 1))";
+    let normalized = "CREATE TABLE t (x INT, CHECK (x > 1))";
+    mysql_and_generic().one_statement_parses_to(sql, normalized);

Review Comment:
   can we use `all_dialects_where()` to select the dialects?



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