File tree 3 files changed +20
-2
lines changed
3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -1142,6 +1142,8 @@ pub enum Statement {
1142
1142
#[ cfg_attr( feature = "visitor" , visit( with = "visit_relation" ) ) ]
1143
1143
table_name : ObjectName ,
1144
1144
partitions : Option < Vec < Expr > > ,
1145
+ /// TABLE - optional keyword;
1146
+ table : bool ,
1145
1147
} ,
1146
1148
/// Msck (Hive)
1147
1149
Msck {
@@ -1844,8 +1846,10 @@ impl fmt::Display for Statement {
1844
1846
Statement :: Truncate {
1845
1847
table_name,
1846
1848
partitions,
1849
+ table,
1847
1850
} => {
1848
- write ! ( f, "TRUNCATE TABLE {table_name}" ) ?;
1851
+ let table = if * table { "TABLE " } else { "" } ;
1852
+ write ! ( f, "TRUNCATE {table}{table_name}" ) ?;
1849
1853
if let Some ( ref parts) = partitions {
1850
1854
if !parts. is_empty ( ) {
1851
1855
write ! ( f, " PARTITION ({})" , display_comma_separated( parts) ) ?;
Original file line number Diff line number Diff line change @@ -473,7 +473,7 @@ impl<'a> Parser<'a> {
473
473
}
474
474
475
475
pub fn parse_truncate ( & mut self ) -> Result < Statement , ParserError > {
476
- self . expect_keyword ( Keyword :: TABLE ) ? ;
476
+ let table = self . parse_keyword ( Keyword :: TABLE ) ;
477
477
let table_name = self . parse_object_name ( ) ?;
478
478
let mut partitions = None ;
479
479
if self . parse_keyword ( Keyword :: PARTITION ) {
@@ -484,6 +484,7 @@ impl<'a> Parser<'a> {
484
484
Ok ( Statement :: Truncate {
485
485
table_name,
486
486
partitions,
487
+ table,
487
488
} )
488
489
}
489
490
Original file line number Diff line number Diff line change @@ -2950,3 +2950,16 @@ fn parse_select_group_by_cube() {
2950
2950
select. group_by
2951
2951
) ;
2952
2952
}
2953
+
2954
+ #[ test]
2955
+ fn parse_truncate ( ) {
2956
+ let truncate = pg_and_generic ( ) . verified_stmt ( "TRUNCATE db.table_name" ) ;
2957
+ assert_eq ! (
2958
+ Statement :: Truncate {
2959
+ table_name: ObjectName ( vec![ Ident :: new( "db" ) , Ident :: new( "table_name" ) ] ) ,
2960
+ partitions: None ,
2961
+ table: false
2962
+ } ,
2963
+ truncate
2964
+ ) ;
2965
+ }
You can’t perform that action at this time.
0 commit comments