@@ -118,8 +118,6 @@ pub struct Insert {
118118
119119impl Display for Insert {
120120 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
121- let is_multi_table = self . multi_table_insert_type . is_some ( ) ;
122-
123121 // SQLite OR conflict has a special format: INSERT OR ... INTO table_name
124122 if let Some ( on_conflict) = self . or {
125123 let table_name: String = if let Some ( alias) = & self . table_alias {
@@ -159,39 +157,36 @@ impl Display for Insert {
159157 write ! ( f, " TABLE" ) ?;
160158 }
161159
162- if !is_multi_table {
163- let table_name = if let Some ( alias) = & self . table_alias {
164- format ! ( "{0} AS {alias}" , self . table )
165- } else {
166- self . table . to_string ( )
167- } ;
160+ let table_name = if let Some ( alias ) = & self . table_alias {
161+ format ! ( "{0} AS { alias}" , self . table )
162+ } else {
163+ self . table . to_string ( )
164+ } ;
165+ if !table_name . is_empty ( ) {
168166 write ! ( f, " {table_name} " ) ?;
169167 }
170168 }
171169
172- if !is_multi_table && ! self . columns . is_empty ( ) {
170+ if !self . columns . is_empty ( ) {
173171 write ! ( f, "({})" , display_comma_separated( & self . columns) ) ?;
174172 SpaceOrNewline . fmt ( f) ?;
175173 }
176- if !is_multi_table {
177- if let Some ( ref parts) = self . partitioned {
178- if !parts. is_empty ( ) {
179- write ! ( f, "PARTITION ({})" , display_comma_separated( parts) ) ?;
180- SpaceOrNewline . fmt ( f) ?;
181- }
174+
175+ if let Some ( ref parts) = self . partitioned {
176+ if !parts. is_empty ( ) {
177+ write ! ( f, "PARTITION ({})" , display_comma_separated( parts) ) ?;
178+ SpaceOrNewline . fmt ( f) ?;
182179 }
183180 }
184181
185- if !is_multi_table && ! self . after_columns . is_empty ( ) {
182+ if !self . after_columns . is_empty ( ) {
186183 write ! ( f, "({})" , display_comma_separated( & self . after_columns) ) ?;
187184 SpaceOrNewline . fmt ( f) ?;
188185 }
189186
190- if !is_multi_table {
191- if let Some ( settings) = & self . settings {
192- write ! ( f, "SETTINGS {}" , display_comma_separated( settings) ) ?;
193- SpaceOrNewline . fmt ( f) ?;
194- }
187+ if let Some ( settings) = & self . settings {
188+ write ! ( f, "SETTINGS {}" , display_comma_separated( settings) ) ?;
189+ SpaceOrNewline . fmt ( f) ?;
195190 }
196191
197192 for into_clause in & self . multi_table_into_clauses {
@@ -213,48 +208,40 @@ impl Display for Insert {
213208 }
214209 }
215210
216- if is_multi_table {
217- if let Some ( source) = & self . source {
211+ if let Some ( source) = & self . source {
212+ if !self . multi_table_into_clauses . is_empty ( )
213+ || !self . multi_table_when_clauses . is_empty ( )
214+ {
218215 SpaceOrNewline . fmt ( f) ?;
219- source. fmt ( f) ?;
220- }
221- } else {
222- if let Some ( source) = & self . source {
223- source. fmt ( f) ?;
224- } else if !self . assignments . is_empty ( ) {
225- write ! ( f, "SET" ) ?;
226- indented_list ( f, & self . assignments ) ?;
227- } else if let Some ( format_clause) = & self . format_clause {
228- format_clause. fmt ( f) ?;
229- } else if self . columns . is_empty ( ) {
230- write ! ( f, "DEFAULT VALUES" ) ?;
231216 }
217+ source. fmt ( f) ?;
218+ } else if !self . assignments . is_empty ( ) {
219+ write ! ( f, "SET" ) ?;
220+ indented_list ( f, & self . assignments ) ?;
221+ } else if let Some ( format_clause) = & self . format_clause {
222+ format_clause. fmt ( f) ?;
223+ } else if self . columns . is_empty ( ) {
224+ write ! ( f, "DEFAULT VALUES" ) ?;
232225 }
233226
234- if !is_multi_table {
235- if let Some ( insert_alias) = & self . insert_alias {
236- write ! ( f, " AS {0}" , insert_alias. row_alias) ?;
227+ if let Some ( insert_alias) = & self . insert_alias {
228+ write ! ( f, " AS {0}" , insert_alias. row_alias) ?;
237229
238- if let Some ( col_aliases) = & insert_alias. col_aliases {
239- if !col_aliases. is_empty ( ) {
240- write ! ( f, " ({})" , display_comma_separated( col_aliases) ) ?;
241- }
230+ if let Some ( col_aliases) = & insert_alias. col_aliases {
231+ if !col_aliases. is_empty ( ) {
232+ write ! ( f, " ({})" , display_comma_separated( col_aliases) ) ?;
242233 }
243234 }
244235 }
245236
246- if !is_multi_table {
247- if let Some ( on) = & self . on {
248- write ! ( f, "{on}" ) ?;
249- }
237+ if let Some ( on) = & self . on {
238+ write ! ( f, "{on}" ) ?;
250239 }
251240
252- if !is_multi_table {
253- if let Some ( returning) = & self . returning {
254- SpaceOrNewline . fmt ( f) ?;
255- f. write_str ( "RETURNING" ) ?;
256- indented_list ( f, returning) ?;
257- }
241+ if let Some ( returning) = & self . returning {
242+ SpaceOrNewline . fmt ( f) ?;
243+ f. write_str ( "RETURNING" ) ?;
244+ indented_list ( f, returning) ?;
258245 }
259246
260247 Ok ( ( ) )
0 commit comments