1#[cfg(not(feature = "std"))]
19use alloc::{boxed::Box, format, string::ToString, vec::Vec};
20
21use core::fmt::{self, Display};
22#[cfg(feature = "serde")]
23use serde::{Deserialize, Serialize};
24#[cfg(feature = "visitor")]
25use sqlparser_derive::{Visit, VisitMut};
26
27use crate::{
28 ast::display_separated,
29 display_utils::{indented_list, Indent, SpaceOrNewline},
30};
31
32use super::{
33 display_comma_separated, helpers::attached_token::AttachedToken, query::InputFormatClause,
34 Assignment, Expr, FromTable, Ident, InsertAliases, MysqlInsertPriority, ObjectName, OnInsert,
35 OptimizerHint, OrderByExpr, Query, SelectInto, SelectItem, Setting, SqliteOnConflict,
36 TableAliasWithoutColumns, TableFactor, TableObject, TableWithJoins, UpdateTableFromKind,
37 Values,
38};
39
40#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
45#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
46#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
47pub enum InsertOverriding {
48 System,
50 User,
52}
53
54impl Display for InsertOverriding {
55 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56 match self {
57 InsertOverriding::System => write!(f, "OVERRIDING SYSTEM VALUE"),
58 InsertOverriding::User => write!(f, "OVERRIDING USER VALUE"),
59 }
60 }
61}
62
63#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
65#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
66#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
67pub struct Insert {
68 pub insert_token: AttachedToken,
70 pub optimizer_hints: Vec<OptimizerHint>,
75 pub or: Option<SqliteOnConflict>,
77 pub ignore: bool,
79 pub into: bool,
81 pub table: TableObject,
83 pub table_alias: Option<TableAliasWithoutColumns>,
86 pub columns: Vec<ObjectName>,
88 pub by_name: bool,
102 pub overwrite: bool,
104 pub source: Option<Box<Query>>,
106 pub assignments: Vec<Assignment>,
109 pub partitioned: Option<Vec<Expr>>,
111 pub after_columns: Vec<Ident>,
113 pub overriding: Option<InsertOverriding>,
117 pub has_table_keyword: bool,
119 pub on: Option<OnInsert>,
121 pub returning: Option<Vec<SelectItem>>,
123 pub output: Option<OutputClause>,
126 pub replace_into: bool,
128 pub priority: Option<MysqlInsertPriority>,
130 pub insert_alias: Option<InsertAliases>,
132 pub settings: Option<Vec<Setting>>,
138 pub format_clause: Option<InputFormatClause>,
145 pub multi_table_insert_type: Option<MultiTableInsertType>,
153 pub multi_table_into_clauses: Vec<MultiTableInsertIntoClause>,
159 pub multi_table_when_clauses: Vec<MultiTableInsertWhenClause>,
165 pub multi_table_else_clause: Option<Vec<MultiTableInsertIntoClause>>,
169}
170
171impl Display for Insert {
172 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
173 let table_name = if let Some(table_alias) = &self.table_alias {
175 format!(
176 "{table} {as_keyword}{alias}",
177 table = self.table,
178 as_keyword = if table_alias.explicit { "AS " } else { "" },
179 alias = table_alias.alias
180 )
181 } else {
182 self.table.to_string()
183 };
184
185 if let Some(on_conflict) = self.or {
186 f.write_str("INSERT")?;
187 for hint in &self.optimizer_hints {
188 write!(f, " {hint}")?;
189 }
190 write!(f, " {on_conflict} INTO {table_name} ")?;
191 } else {
192 write!(
193 f,
194 "{start}",
195 start = if self.replace_into {
196 "REPLACE"
197 } else {
198 "INSERT"
199 }
200 )?;
201 for hint in &self.optimizer_hints {
202 write!(f, " {hint}")?;
203 }
204 if let Some(priority) = self.priority {
205 write!(f, " {priority}")?;
206 }
207
208 if self.ignore {
209 write!(f, " IGNORE")?;
210 }
211
212 if self.overwrite {
213 write!(f, " OVERWRITE")?;
214 }
215
216 if let Some(insert_type) = &self.multi_table_insert_type {
217 write!(f, " {}", insert_type)?;
218 }
219
220 if self.into {
221 write!(f, " INTO")?;
222 }
223
224 if self.has_table_keyword {
225 write!(f, " TABLE")?;
226 }
227
228 if !table_name.is_empty() {
229 write!(f, " {table_name} ")?;
230 }
231 }
232
233 if !self.columns.is_empty() {
234 write!(f, "({})", display_comma_separated(&self.columns))?;
235 SpaceOrNewline.fmt(f)?;
236 }
237
238 if let Some(ref parts) = self.partitioned {
239 if !parts.is_empty() {
240 write!(f, "PARTITION ({})", display_comma_separated(parts))?;
241 SpaceOrNewline.fmt(f)?;
242 }
243 }
244
245 if self.by_name {
246 write!(f, "BY NAME")?;
247 SpaceOrNewline.fmt(f)?;
248 }
249
250 if !self.after_columns.is_empty() {
251 write!(f, "({})", display_comma_separated(&self.after_columns))?;
252 SpaceOrNewline.fmt(f)?;
253 }
254
255 if let Some(overriding) = &self.overriding {
256 write!(f, "{overriding}")?;
257 SpaceOrNewline.fmt(f)?;
258 }
259
260 if let Some(output) = &self.output {
261 write!(f, "{output}")?;
262 SpaceOrNewline.fmt(f)?;
263 }
264
265 if let Some(settings) = &self.settings {
266 write!(f, "SETTINGS {}", display_comma_separated(settings))?;
267 SpaceOrNewline.fmt(f)?;
268 }
269
270 for into_clause in &self.multi_table_into_clauses {
271 SpaceOrNewline.fmt(f)?;
272 write!(f, "{}", into_clause)?;
273 }
274
275 for when_clause in &self.multi_table_when_clauses {
276 SpaceOrNewline.fmt(f)?;
277 write!(f, "{}", when_clause)?;
278 }
279
280 if let Some(else_clauses) = &self.multi_table_else_clause {
281 SpaceOrNewline.fmt(f)?;
282 write!(f, "ELSE")?;
283 for into_clause in else_clauses {
284 SpaceOrNewline.fmt(f)?;
285 write!(f, "{}", into_clause)?;
286 }
287 }
288
289 if let Some(source) = &self.source {
290 if !self.multi_table_into_clauses.is_empty()
291 || !self.multi_table_when_clauses.is_empty()
292 {
293 SpaceOrNewline.fmt(f)?;
294 }
295 source.fmt(f)?;
296 } else if !self.assignments.is_empty() {
297 write!(f, "SET")?;
298 indented_list(f, &self.assignments)?;
299 } else if let Some(format_clause) = &self.format_clause {
300 format_clause.fmt(f)?;
301 } else if self.columns.is_empty() {
302 write!(f, "DEFAULT VALUES")?;
303 }
304
305 if let Some(insert_alias) = &self.insert_alias {
306 write!(f, " AS {0}", insert_alias.row_alias)?;
307
308 if let Some(col_aliases) = &insert_alias.col_aliases {
309 if !col_aliases.is_empty() {
310 write!(f, " ({})", display_comma_separated(col_aliases))?;
311 }
312 }
313 }
314
315 if let Some(on) = &self.on {
316 write!(f, "{on}")?;
317 }
318
319 if let Some(returning) = &self.returning {
320 SpaceOrNewline.fmt(f)?;
321 f.write_str("RETURNING")?;
322 indented_list(f, returning)?;
323 }
324
325 Ok(())
326 }
327}
328
329#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
331#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
332#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
333pub struct Delete {
334 pub delete_token: AttachedToken,
336 pub optimizer_hints: Vec<OptimizerHint>,
341 pub tables: Vec<ObjectName>,
343 pub from: FromTable,
345 pub on_cluster: Option<Ident>,
347 pub using: Option<Vec<TableWithJoins>>,
349 pub selection: Option<Expr>,
351 pub returning: Option<Vec<SelectItem>>,
353 pub output: Option<OutputClause>,
356 pub order_by: Vec<OrderByExpr>,
358 pub limit: Option<Expr>,
360 pub settings: Option<Vec<Setting>>,
362}
363
364impl Display for Delete {
365 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
366 f.write_str("DELETE")?;
367 for hint in &self.optimizer_hints {
368 f.write_str(" ")?;
369 hint.fmt(f)?;
370 }
371 if !self.tables.is_empty() {
372 indented_list(f, &self.tables)?;
373 }
374 match &self.from {
375 FromTable::WithFromKeyword(from) => {
376 f.write_str(" FROM")?;
377 indented_list(f, from)?;
378 }
379 FromTable::WithoutKeyword(from) => {
380 indented_list(f, from)?;
381 }
382 }
383 if let Some(on_cluster) = &self.on_cluster {
384 write!(f, " ON CLUSTER {on_cluster}")?;
385 }
386 if let Some(output) = &self.output {
387 SpaceOrNewline.fmt(f)?;
388 write!(f, "{output}")?;
389 }
390 if let Some(using) = &self.using {
391 SpaceOrNewline.fmt(f)?;
392 f.write_str("USING")?;
393 indented_list(f, using)?;
394 }
395 if let Some(selection) = &self.selection {
396 SpaceOrNewline.fmt(f)?;
397 f.write_str("WHERE")?;
398 SpaceOrNewline.fmt(f)?;
399 Indent(selection).fmt(f)?;
400 }
401 if let Some(returning) = &self.returning {
402 SpaceOrNewline.fmt(f)?;
403 f.write_str("RETURNING")?;
404 indented_list(f, returning)?;
405 }
406 if !self.order_by.is_empty() {
407 SpaceOrNewline.fmt(f)?;
408 f.write_str("ORDER BY")?;
409 indented_list(f, &self.order_by)?;
410 }
411 if let Some(limit) = &self.limit {
412 SpaceOrNewline.fmt(f)?;
413 f.write_str("LIMIT")?;
414 SpaceOrNewline.fmt(f)?;
415 Indent(limit).fmt(f)?;
416 }
417 if let Some(settings) = &self.settings {
418 SpaceOrNewline.fmt(f)?;
419 f.write_str("SETTINGS")?;
420 indented_list(f, settings)?;
421 }
422 Ok(())
423 }
424}
425
426#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
428#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
429#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
430pub struct Update {
431 pub update_token: AttachedToken,
433 pub optimizer_hints: Vec<OptimizerHint>,
438 pub table: TableWithJoins,
440 pub on_cluster: Option<Ident>,
442 pub assignments: Vec<Assignment>,
444 pub from: Option<UpdateTableFromKind>,
446 pub selection: Option<Expr>,
448 pub returning: Option<Vec<SelectItem>>,
450 pub output: Option<OutputClause>,
453 pub or: Option<SqliteOnConflict>,
455 pub order_by: Vec<OrderByExpr>,
458 pub limit: Option<Expr>,
460 pub settings: Option<Vec<Setting>>,
462}
463
464impl Display for Update {
465 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
466 f.write_str("UPDATE")?;
467 for hint in &self.optimizer_hints {
468 f.write_str(" ")?;
469 hint.fmt(f)?;
470 }
471 f.write_str(" ")?;
472 if let Some(or) = &self.or {
473 or.fmt(f)?;
474 f.write_str(" ")?;
475 }
476 self.table.fmt(f)?;
477 if let Some(on_cluster) = &self.on_cluster {
478 write!(f, " ON CLUSTER {on_cluster}")?;
479 }
480 if let Some(UpdateTableFromKind::BeforeSet(from)) = &self.from {
481 SpaceOrNewline.fmt(f)?;
482 f.write_str("FROM")?;
483 indented_list(f, from)?;
484 }
485 if !self.assignments.is_empty() {
486 SpaceOrNewline.fmt(f)?;
487 f.write_str("SET")?;
488 indented_list(f, &self.assignments)?;
489 }
490 if let Some(output) = &self.output {
491 SpaceOrNewline.fmt(f)?;
492 write!(f, "{output}")?;
493 }
494 if let Some(UpdateTableFromKind::AfterSet(from)) = &self.from {
495 SpaceOrNewline.fmt(f)?;
496 f.write_str("FROM")?;
497 indented_list(f, from)?;
498 }
499 if let Some(selection) = &self.selection {
500 SpaceOrNewline.fmt(f)?;
501 f.write_str("WHERE")?;
502 SpaceOrNewline.fmt(f)?;
503 Indent(selection).fmt(f)?;
504 }
505 if let Some(returning) = &self.returning {
506 SpaceOrNewline.fmt(f)?;
507 f.write_str("RETURNING")?;
508 indented_list(f, returning)?;
509 }
510 if !self.order_by.is_empty() {
511 SpaceOrNewline.fmt(f)?;
512 f.write_str("ORDER BY")?;
513 indented_list(f, &self.order_by)?;
514 }
515 if let Some(limit) = &self.limit {
516 SpaceOrNewline.fmt(f)?;
517 write!(f, "LIMIT {limit}")?;
518 }
519 if let Some(settings) = &self.settings {
520 SpaceOrNewline.fmt(f)?;
521 f.write_str("SETTINGS")?;
522 indented_list(f, settings)?;
523 }
524 Ok(())
525 }
526}
527
528#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
530#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
531#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
532pub struct Merge {
533 pub merge_token: AttachedToken,
535 pub optimizer_hints: Vec<OptimizerHint>,
539 pub into: bool,
541 pub table: TableFactor,
543 pub source: TableFactor,
545 pub on: Box<Expr>,
547 pub clauses: Vec<MergeClause>,
549 pub output: Option<OutputClause>,
551}
552
553impl Display for Merge {
554 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
555 f.write_str("MERGE")?;
556 for hint in &self.optimizer_hints {
557 write!(f, " {hint}")?;
558 }
559 if self.into {
560 write!(f, " INTO")?;
561 }
562 write!(
563 f,
564 " {table} USING {source} ",
565 table = self.table,
566 source = self.source
567 )?;
568 write!(f, "ON {on} ", on = self.on)?;
569 write!(f, "{}", display_separated(&self.clauses, " "))?;
570 if let Some(ref output) = self.output {
571 write!(f, " {output}")?;
572 }
573 Ok(())
574 }
575}
576
577#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
586#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
587#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
588pub struct MergeClause {
589 pub when_token: AttachedToken,
591 pub clause_kind: MergeClauseKind,
593 pub predicate: Option<Expr>,
595 pub action: MergeAction,
597}
598
599impl Display for MergeClause {
600 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
601 let MergeClause {
602 when_token: _,
603 clause_kind,
604 predicate,
605 action,
606 } = self;
607
608 write!(f, "WHEN {clause_kind}")?;
609 if let Some(pred) = predicate {
610 write!(f, " AND {pred}")?;
611 }
612 write!(f, " THEN {action}")
613 }
614}
615
616#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
625#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
626#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
627pub enum MergeClauseKind {
628 Matched,
630 NotMatched,
632 NotMatchedByTarget,
636 NotMatchedBySource,
640}
641
642impl Display for MergeClauseKind {
643 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
644 match self {
645 MergeClauseKind::Matched => write!(f, "MATCHED"),
646 MergeClauseKind::NotMatched => write!(f, "NOT MATCHED"),
647 MergeClauseKind::NotMatchedByTarget => write!(f, "NOT MATCHED BY TARGET"),
648 MergeClauseKind::NotMatchedBySource => write!(f, "NOT MATCHED BY SOURCE"),
649 }
650 }
651}
652
653#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
664#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
665#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
666pub enum MergeAction {
667 Insert(MergeInsertExpr),
674 Update(MergeUpdateExpr),
681 Delete {
683 delete_token: AttachedToken,
685 },
686 DoNothing {
688 do_token: AttachedToken,
690 nothing_token: AttachedToken,
692 },
693}
694
695impl Display for MergeAction {
696 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
697 match self {
698 MergeAction::Insert(insert) => {
699 write!(f, "INSERT {insert}")
700 }
701 MergeAction::Update(update) => {
702 write!(f, "UPDATE {update}")
703 }
704 MergeAction::Delete { .. } => {
705 write!(f, "DELETE")
706 }
707 MergeAction::DoNothing { .. } => {
708 write!(f, "DO NOTHING")
709 }
710 }
711 }
712}
713
714#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
719#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
720#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
721pub enum MergeInsertKind {
722 Values(Values),
729 Row,
737 Wildcard,
745}
746
747impl Display for MergeInsertKind {
748 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
749 match self {
750 MergeInsertKind::Values(values) => {
751 write!(f, "{values}")
752 }
753 MergeInsertKind::Row => {
754 write!(f, "ROW")
755 }
756 MergeInsertKind::Wildcard => {
757 write!(f, "*")
758 }
759 }
760 }
761}
762
763#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
775#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
776#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
777pub struct MergeInsertExpr {
778 pub insert_token: AttachedToken,
780 pub columns: Vec<ObjectName>,
788 pub kind_token: AttachedToken,
790 pub kind: MergeInsertKind,
792 pub insert_predicate: Option<Expr>,
794}
795
796impl Display for MergeInsertExpr {
797 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
798 if !self.columns.is_empty() {
799 write!(f, "({}) ", display_comma_separated(self.columns.as_slice()))?;
800 }
801 write!(f, "{}", self.kind)?;
802 if let Some(predicate) = self.insert_predicate.as_ref() {
803 write!(f, " WHERE {}", predicate)?;
804 }
805 Ok(())
806 }
807}
808
809#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
811#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
812#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
813pub enum MergeUpdateKind {
814 Set(Vec<Assignment>),
821 Wildcard,
829}
830
831impl Display for MergeUpdateKind {
832 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
833 match self {
834 MergeUpdateKind::Set(assignments) => {
835 write!(f, "SET {}", display_comma_separated(assignments))
836 }
837 MergeUpdateKind::Wildcard => {
838 write!(f, "SET *")
839 }
840 }
841 }
842}
843
844#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
857#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
858#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
859pub struct MergeUpdateExpr {
860 pub update_token: AttachedToken,
862 pub kind: MergeUpdateKind,
864 pub update_predicate: Option<Expr>,
866 pub delete_predicate: Option<Expr>,
868}
869
870impl Display for MergeUpdateExpr {
871 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
872 write!(f, "{}", self.kind)?;
873 if let Some(predicate) = self.update_predicate.as_ref() {
874 write!(f, " WHERE {predicate}")?;
875 }
876 if let Some(predicate) = self.delete_predicate.as_ref() {
877 write!(f, " DELETE WHERE {predicate}")?;
878 }
879 Ok(())
880 }
881}
882
883#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
889#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
890#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
891pub enum OutputClause {
892 Output {
894 output_token: AttachedToken,
896 select_items: Vec<SelectItem>,
898 into_table: Option<SelectInto>,
900 },
901 Returning {
903 returning_token: AttachedToken,
905 select_items: Vec<SelectItem>,
907 },
908}
909
910impl fmt::Display for OutputClause {
911 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
912 match self {
913 OutputClause::Output {
914 output_token: _,
915 select_items,
916 into_table,
917 } => {
918 f.write_str("OUTPUT ")?;
919 display_comma_separated(select_items).fmt(f)?;
920 if let Some(into_table) = into_table {
921 f.write_str(" ")?;
922 into_table.fmt(f)?;
923 }
924 Ok(())
925 }
926 OutputClause::Returning {
927 returning_token: _,
928 select_items,
929 } => {
930 f.write_str("RETURNING ")?;
931 display_comma_separated(select_items).fmt(f)
932 }
933 }
934 }
935}
936
937#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
946#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
947#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
948pub struct MultiTableInsertWhenClause {
949 pub condition: Expr,
951 pub into_clauses: Vec<MultiTableInsertIntoClause>,
953}
954
955impl Display for MultiTableInsertWhenClause {
956 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
957 write!(f, "WHEN {} THEN", self.condition)?;
958 for into_clause in &self.into_clauses {
959 SpaceOrNewline.fmt(f)?;
960 write!(f, "{}", into_clause)?;
961 }
962 Ok(())
963 }
964}
965
966#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
973#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
974#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
975pub struct MultiTableInsertIntoClause {
976 pub table_name: ObjectName,
978 pub columns: Vec<Ident>,
980 pub values: Option<MultiTableInsertValues>,
982}
983
984impl Display for MultiTableInsertIntoClause {
985 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
986 write!(f, "INTO {}", self.table_name)?;
987 if !self.columns.is_empty() {
988 write!(f, " ({})", display_comma_separated(&self.columns))?;
989 }
990 if let Some(values) = &self.values {
991 write!(f, " VALUES ({})", display_comma_separated(&values.values))?;
992 }
993 Ok(())
994 }
995}
996
997#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
999#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1000#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1001pub struct MultiTableInsertValues {
1002 pub values: Vec<MultiTableInsertValue>,
1004}
1005
1006#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1008#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1009#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1010pub enum MultiTableInsertValue {
1011 Expr(Expr),
1013 Default,
1015}
1016
1017impl Display for MultiTableInsertValue {
1018 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1019 match self {
1020 MultiTableInsertValue::Expr(expr) => write!(f, "{}", expr),
1021 MultiTableInsertValue::Default => write!(f, "DEFAULT"),
1022 }
1023 }
1024}
1025
1026#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1030#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1031#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1032pub enum MultiTableInsertType {
1033 All,
1035 First,
1037}
1038
1039impl Display for MultiTableInsertType {
1040 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1041 match self {
1042 MultiTableInsertType::All => write!(f, "ALL"),
1043 MultiTableInsertType::First => write!(f, "FIRST"),
1044 }
1045 }
1046}