@@ -2176,6 +2176,18 @@ pub enum FromTable {
2176
2176
/// <https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#delete_statement>
2177
2177
WithoutKeyword ( Vec < TableWithJoins > ) ,
2178
2178
}
2179
+ impl Display for FromTable {
2180
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2181
+ match self {
2182
+ FromTable :: WithFromKeyword ( tables) => {
2183
+ write ! ( f, "FROM {}" , display_comma_separated( tables) )
2184
+ }
2185
+ FromTable :: WithoutKeyword ( tables) => {
2186
+ write ! ( f, "{}" , display_comma_separated( tables) )
2187
+ }
2188
+ }
2189
+ }
2190
+ }
2179
2191
2180
2192
/// Policy type for a `CREATE POLICY` statement.
2181
2193
/// ```sql
@@ -3533,93 +3545,7 @@ impl fmt::Display for Statement {
3533
3545
}
3534
3546
Ok ( ( ) )
3535
3547
}
3536
- Statement :: Insert ( insert) => {
3537
- let Insert {
3538
- or,
3539
- ignore,
3540
- into,
3541
- table_name,
3542
- table_alias,
3543
- overwrite,
3544
- partitioned,
3545
- columns,
3546
- after_columns,
3547
- source,
3548
- table,
3549
- on,
3550
- returning,
3551
- replace_into,
3552
- priority,
3553
- insert_alias,
3554
- } = insert;
3555
- let table_name = if let Some ( alias) = table_alias {
3556
- format ! ( "{table_name} AS {alias}" )
3557
- } else {
3558
- table_name. to_string ( )
3559
- } ;
3560
-
3561
- if let Some ( action) = or {
3562
- write ! ( f, "INSERT OR {action} INTO {table_name} " ) ?;
3563
- } else {
3564
- write ! (
3565
- f,
3566
- "{start}" ,
3567
- start = if * replace_into { "REPLACE" } else { "INSERT" } ,
3568
- ) ?;
3569
- if let Some ( priority) = priority {
3570
- write ! ( f, " {priority}" , ) ?;
3571
- }
3572
-
3573
- write ! (
3574
- f,
3575
- "{ignore}{over}{int}{tbl} {table_name} " ,
3576
- table_name = table_name,
3577
- ignore = if * ignore { " IGNORE" } else { "" } ,
3578
- over = if * overwrite { " OVERWRITE" } else { "" } ,
3579
- int = if * into { " INTO" } else { "" } ,
3580
- tbl = if * table { " TABLE" } else { "" } ,
3581
- ) ?;
3582
- }
3583
- if !columns. is_empty ( ) {
3584
- write ! ( f, "({}) " , display_comma_separated( columns) ) ?;
3585
- }
3586
- if let Some ( ref parts) = partitioned {
3587
- if !parts. is_empty ( ) {
3588
- write ! ( f, "PARTITION ({}) " , display_comma_separated( parts) ) ?;
3589
- }
3590
- }
3591
- if !after_columns. is_empty ( ) {
3592
- write ! ( f, "({}) " , display_comma_separated( after_columns) ) ?;
3593
- }
3594
-
3595
- if let Some ( source) = source {
3596
- write ! ( f, "{source}" ) ?;
3597
- }
3598
-
3599
- if source. is_none ( ) && columns. is_empty ( ) {
3600
- write ! ( f, "DEFAULT VALUES" ) ?;
3601
- }
3602
-
3603
- if let Some ( insert_alias) = insert_alias {
3604
- write ! ( f, " AS {0}" , insert_alias. row_alias) ?;
3605
-
3606
- if let Some ( col_aliases) = & insert_alias. col_aliases {
3607
- if !col_aliases. is_empty ( ) {
3608
- write ! ( f, " ({})" , display_comma_separated( col_aliases) ) ?;
3609
- }
3610
- }
3611
- }
3612
-
3613
- if let Some ( on) = on {
3614
- write ! ( f, "{on}" ) ?;
3615
- }
3616
-
3617
- if let Some ( returning) = returning {
3618
- write ! ( f, " RETURNING {}" , display_comma_separated( returning) ) ?;
3619
- }
3620
-
3621
- Ok ( ( ) )
3622
- }
3548
+ Statement :: Insert ( insert) => write ! ( f, "{insert}" ) ,
3623
3549
Statement :: Install {
3624
3550
extension_name : name,
3625
3551
} => write ! ( f, "INSTALL {name}" ) ,
@@ -3696,45 +3622,7 @@ impl fmt::Display for Statement {
3696
3622
}
3697
3623
Ok ( ( ) )
3698
3624
}
3699
- Statement :: Delete ( delete) => {
3700
- let Delete {
3701
- tables,
3702
- from,
3703
- using,
3704
- selection,
3705
- returning,
3706
- order_by,
3707
- limit,
3708
- } = delete;
3709
- write ! ( f, "DELETE " ) ?;
3710
- if !tables. is_empty ( ) {
3711
- write ! ( f, "{} " , display_comma_separated( tables) ) ?;
3712
- }
3713
- match from {
3714
- FromTable :: WithFromKeyword ( from) => {
3715
- write ! ( f, "FROM {}" , display_comma_separated( from) ) ?;
3716
- }
3717
- FromTable :: WithoutKeyword ( from) => {
3718
- write ! ( f, "{}" , display_comma_separated( from) ) ?;
3719
- }
3720
- }
3721
- if let Some ( using) = using {
3722
- write ! ( f, " USING {}" , display_comma_separated( using) ) ?;
3723
- }
3724
- if let Some ( selection) = selection {
3725
- write ! ( f, " WHERE {selection}" ) ?;
3726
- }
3727
- if let Some ( returning) = returning {
3728
- write ! ( f, " RETURNING {}" , display_comma_separated( returning) ) ?;
3729
- }
3730
- if !order_by. is_empty ( ) {
3731
- write ! ( f, " ORDER BY {}" , display_comma_separated( order_by) ) ?;
3732
- }
3733
- if let Some ( limit) = limit {
3734
- write ! ( f, " LIMIT {limit}" ) ?;
3735
- }
3736
- Ok ( ( ) )
3737
- }
3625
+ Statement :: Delete ( delete) => write ! ( f, "{delete}" ) ,
3738
3626
Statement :: Close { cursor } => {
3739
3627
write ! ( f, "CLOSE {cursor}" ) ?;
3740
3628
0 commit comments