finchxxia commented on code in PR #2148:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2148#discussion_r2745438508


##########
src/ast/dml.rs:
##########
@@ -90,92 +90,174 @@ pub struct Insert {
     ///
     /// [ClickHouse formats JSON 
insert](https://clickhouse.com/docs/en/interfaces/formats#json-inserting-data)
     pub format_clause: Option<InputFormatClause>,
+    /// For multi-table insert: `INSERT FIRST` vs `INSERT ALL`
+    ///
+    /// When `true`, this is an `INSERT FIRST` statement (only the first 
matching WHEN clause is executed).
+    /// When `false` with non-empty `clauses`, this is an `INSERT ALL` 
statement.
+    ///
+    /// See: 
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+    pub insert_first: bool,
+    /// For multi-table insert: additional INTO clauses (unconditional)
+    ///
+    /// Used for `INSERT ALL INTO t1 INTO t2 ... SELECT ...`
+    ///
+    /// See: 
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+    pub multi_table_into_clauses: Vec<MultiTableInsertIntoClause>,
+    /// For conditional multi-table insert: WHEN clauses
+    ///
+    /// Used for `INSERT ALL/FIRST WHEN cond THEN INTO t1 ... SELECT ...`
+    ///
+    /// See: 
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+    pub multi_table_when_clauses: Vec<MultiTableInsertWhenClause>,
+    /// For conditional multi-table insert: ELSE clause
+    ///
+    /// See: 
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+    pub multi_table_else_clause: Option<Vec<MultiTableInsertIntoClause>>,
 }
 
 impl Display for Insert {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        let table_name = if let Some(alias) = &self.table_alias {
-            format!("{0} AS {alias}", self.table)
-        } else {
-            self.table.to_string()
-        };
+        // Check if this is a Snowflake multi-table insert
+        let is_multi_table = !self.multi_table_into_clauses.is_empty()
+            || !self.multi_table_when_clauses.is_empty();

Review Comment:
   > Oh so here's an example to clarify what I meant in the previous comment. 
If we take this block in the display logic
   
   @iffyio Oh, sorry for misinterpreting your meaning.  That could be different 
between these two code blocks. For example, input query can be:
   
   `INSERT ALL INTO t1 INTO t2 SELECT n1 FROM src`
   
   and if we don't add ` if !is_multi_table`, the output would be:
   ```
   INSERT ALL  INTO t1 INTO t2 SELECT n1 FROM src
              ^^extra space here
   ```
   
   If you don't mind, I can revert my code and add another test for that.



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