LucaCappelletti94 commented on code in PR #2594:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2594#discussion_r4657689728


##########
src/parser/mod.rs:
##########
@@ -16366,19 +16366,18 @@ impl<'a> Parser<'a> {
 
     /// Parse `CREATE TABLE x AS TABLE y`
     pub fn parse_as_table(&mut self) -> Result<Table, ParserError> {
-        let first_name = self.parse_identifier()?;
-        if self.consume_token(&Token::Period) {
-            let second_name = self.parse_identifier()?;
-            Ok(Table {
-                table_name: Some(second_name),
-                schema_name: Some(first_name),
-            })
+        let max_parts = if self.dialect.supports_multipart_table_query_name() {
+            usize::MAX
         } else {
-            Ok(Table {
-                table_name: Some(first_name),
-                schema_name: None,
-            })
+            2
+        };
+        let mut parts = vec![self.parse_identifier()?];
+        while parts.len() < max_parts && self.consume_token(&Token::Period) {
+            parts.push(self.parse_identifier()?);
         }

Review Comment:
   You should drop the two-part cap, since PostgreSQL accepts three-part names 
here too. PostgreSQL 18 runs `CREATE VIEW v AS TABLE postgres.raw.source` and 
`SELECT 1 WHERE 1 IN (TABLE postgres.raw.source)`, while this branch rejects 
both under `PostgreSqlDialect` and `GenericDialect` with `Expected: end of 
statement, found: .`. With `Table` holding an `ObjectName`, nothing depends on 
the cap any more.
   
   I cannot add the suggestion in the github tool for some reason, but 
something like:
   
   ```rust
           let mut parts = vec![self.parse_identifier()?];
           while self.consume_token(&Token::Period) {
               parts.push(self.parse_identifier()?);
           }
   ```



##########
src/dialect/mod.rs:
##########
@@ -1254,6 +1254,11 @@ pub trait Dialect: Debug + Any {
         false
     }
 
+    /// Returns true if `TABLE` queries accept names with more than two parts.
+    fn supports_multipart_table_query_name(&self) -> bool {
+        false
+    }
+

Review Comment:
   You should remove this hook, because once the parser takes any number of 
parts it has no callers. As a public `Dialect` method, removing it after a 
release would be a breaking change.
   
   ```suggestion
   ```



##########
tests/sqlparser_common.rs:
##########


Review Comment:
   You should add a three-part case that runs across all dialects. It fails on 
this branch under `GenericDialect` and catches the cap if it ever comes back.
   
   ```suggestion
   
       verified_stmt("CREATE TABLE new_table AS TABLE 
db_name.schema_name.old_table");
   }
   ```



##########
src/dialect/databricks.rs:
##########
@@ -146,6 +146,10 @@ impl Dialect for DatabricksDialect {
         true
     }
 
+    fn supports_multipart_table_query_name(&self) -> bool {
+        true
+    }
+

Review Comment:
   You should remove this override together with the trait method, or the crate 
stops compiling.
   
   ```suggestion
   ```



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