@@ -90,13 +90,14 @@ pub struct Insert {
9090 ///
9191 /// [ClickHouse formats JSON insert](https://clickhouse.com/docs/en/interfaces/formats#json-inserting-data)
9292 pub format_clause : Option < InputFormatClause > ,
93- /// For multi-table insert: `INSERT FIRST` vs `INSERT ALL`
93+ /// For Snowflake multi-table insert: specifies the type (` ALL` or `FIRST`)
9494 ///
95- /// When `true`, this is an `INSERT FIRST` statement (only the first matching WHEN clause is executed).
96- /// When `false` with non-empty `clauses`, this is an `INSERT ALL` statement.
95+ /// - `None` means this is a regular single-table INSERT
96+ /// - `Some(All)` means `INSERT ALL` (all matching WHEN clauses are executed)
97+ /// - `Some(First)` means `INSERT FIRST` (only the first matching WHEN clause is executed)
9798 ///
9899 /// See: <https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
99- pub insert_first : bool ,
100+ pub multi_table_insert_type : Option < MultiTableInsertType > ,
100101 /// For multi-table insert: additional INTO clauses (unconditional)
101102 ///
102103 /// Used for `INSERT ALL INTO t1 INTO t2 ... SELECT ...`
@@ -117,9 +118,7 @@ pub struct Insert {
117118
118119impl Display for Insert {
119120 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
120- // Check if this is a Snowflake multi-table insert
121- let is_multi_table = !self . multi_table_into_clauses . is_empty ( )
122- || !self . multi_table_when_clauses . is_empty ( ) ;
121+ let is_multi_table = self . multi_table_insert_type . is_some ( ) ;
123122
124123 // SQLite OR conflict has a special format: INSERT OR ... INTO table_name
125124 if let Some ( on_conflict) = self . or {
@@ -148,8 +147,8 @@ impl Display for Insert {
148147 write ! ( f, " OVERWRITE" ) ?;
149148 }
150149
151- if is_multi_table {
152- write ! ( f, " {}" , if self . insert_first { "FIRST" } else { "ALL" } ) ?;
150+ if let Some ( insert_type ) = & self . multi_table_insert_type {
151+ write ! ( f, " {}" , insert_type ) ?;
153152 }
154153
155154 if self . into {
@@ -815,3 +814,25 @@ impl Display for MultiTableInsertValue {
815814 }
816815 }
817816}
817+
818+ /// The type of multi-table INSERT statement(Snowflake).
819+ ///
820+ /// See: <https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
821+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
822+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
823+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
824+ pub enum MultiTableInsertType {
825+ /// `INSERT ALL` - all matching WHEN clauses are executed
826+ All ,
827+ /// `INSERT FIRST` - only the first matching WHEN clause is executed
828+ First ,
829+ }
830+
831+ impl Display for MultiTableInsertType {
832+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
833+ match self {
834+ MultiTableInsertType :: All => write ! ( f, "ALL" ) ,
835+ MultiTableInsertType :: First => write ! ( f, "FIRST" ) ,
836+ }
837+ }
838+ }
0 commit comments