File tree Expand file tree Collapse file tree 7 files changed +28
-12
lines changed Expand file tree Collapse file tree 7 files changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -137,10 +137,10 @@ pub enum AlterTableOperation {
137
137
name : Ident ,
138
138
drop_behavior : Option < DropBehavior > ,
139
139
} ,
140
- /// `DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ CASCADE ]`
140
+ /// `DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ , <column_name>, ... ] [ CASCADE ]`
141
141
DropColumn {
142
142
has_column_keyword : bool ,
143
- column_name : Ident ,
143
+ column_names : Vec < Ident > ,
144
144
if_exists : bool ,
145
145
drop_behavior : Option < DropBehavior > ,
146
146
} ,
@@ -615,15 +615,15 @@ impl fmt::Display for AlterTableOperation {
615
615
AlterTableOperation :: DropIndex { name } => write ! ( f, "DROP INDEX {name}" ) ,
616
616
AlterTableOperation :: DropColumn {
617
617
has_column_keyword,
618
- column_name,
618
+ column_names : column_name,
619
619
if_exists,
620
620
drop_behavior,
621
621
} => write ! (
622
622
f,
623
623
"DROP {}{}{}{}" ,
624
624
if * has_column_keyword { "COLUMN " } else { "" } ,
625
625
if * if_exists { "IF EXISTS " } else { "" } ,
626
- column_name,
626
+ display_comma_separated ( column_name) ,
627
627
match drop_behavior {
628
628
None => "" ,
629
629
Some ( DropBehavior :: Restrict ) => " RESTRICT" ,
Original file line number Diff line number Diff line change @@ -1107,10 +1107,10 @@ impl Spanned for AlterTableOperation {
1107
1107
} => name. span ,
1108
1108
AlterTableOperation :: DropColumn {
1109
1109
has_column_keyword : _,
1110
- column_name ,
1110
+ column_names ,
1111
1111
if_exists : _,
1112
1112
drop_behavior : _,
1113
- } => column_name . span ,
1113
+ } => union_spans ( column_names . iter ( ) . map ( |i| i . span ) ) ,
1114
1114
AlterTableOperation :: AttachPartition { partition } => partition. span ( ) ,
1115
1115
AlterTableOperation :: DetachPartition { partition } => partition. span ( ) ,
1116
1116
AlterTableOperation :: FreezePartition {
Original file line number Diff line number Diff line change @@ -1060,6 +1060,11 @@ pub trait Dialect: Debug + Any {
1060
1060
fn supports_space_separated_column_options ( & self ) -> bool {
1061
1061
false
1062
1062
}
1063
+
1064
+ /// Returns true if the dialect supports `ALTER TABLE tbl DROP COLUMN c1, ..., cn`
1065
+ fn supports_comma_separated_drop_column_list ( & self ) -> bool {
1066
+ false
1067
+ }
1063
1068
}
1064
1069
1065
1070
/// This represents the operators for which precedence must be defined
Original file line number Diff line number Diff line change @@ -364,6 +364,10 @@ impl Dialect for SnowflakeDialect {
364
364
fn supports_space_separated_column_options ( & self ) -> bool {
365
365
true
366
366
}
367
+
368
+ fn supports_comma_separated_drop_column_list ( & self ) -> bool {
369
+ true
370
+ }
367
371
}
368
372
369
373
fn parse_file_staging_command ( kw : Keyword , parser : & mut Parser ) -> Result < Statement , ParserError > {
Original file line number Diff line number Diff line change @@ -8657,11 +8657,15 @@ impl<'a> Parser<'a> {
8657
8657
} else {
8658
8658
let has_column_keyword = self.parse_keyword(Keyword::COLUMN); // [ COLUMN ]
8659
8659
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
8660
- let column_name = self.parse_identifier()?;
8660
+ let column_names = if self.dialect.supports_comma_separated_drop_column_list() {
8661
+ self.parse_comma_separated(Parser::parse_identifier)?
8662
+ } else {
8663
+ vec![self.parse_identifier()?]
8664
+ };
8661
8665
let drop_behavior = self.parse_optional_drop_behavior();
8662
8666
AlterTableOperation::DropColumn {
8663
8667
has_column_keyword,
8664
- column_name ,
8668
+ column_names ,
8665
8669
if_exists,
8666
8670
drop_behavior,
8667
8671
}
Original file line number Diff line number Diff line change @@ -4979,15 +4979,18 @@ fn parse_alter_table_drop_column() {
4979
4979
"ALTER TABLE tab DROP is_active CASCADE",
4980
4980
);
4981
4981
4982
+ let dialects = all_dialects_where(|d| d.supports_comma_separated_drop_column_list());
4983
+ dialects.verified_stmt("ALTER TABLE tbl DROP COLUMN c1, c2, c3");
4984
+
4982
4985
fn check_one(constraint_text: &str) {
4983
4986
match alter_table_op(verified_stmt(&format!("ALTER TABLE tab {constraint_text}"))) {
4984
4987
AlterTableOperation::DropColumn {
4985
4988
has_column_keyword: true,
4986
- column_name ,
4989
+ column_names ,
4987
4990
if_exists,
4988
4991
drop_behavior,
4989
4992
} => {
4990
- assert_eq!("is_active", column_name .to_string());
4993
+ assert_eq!("is_active", column_names.first().unwrap() .to_string());
4991
4994
assert!(if_exists);
4992
4995
match drop_behavior {
4993
4996
None => assert!(constraint_text.ends_with(" is_active")),
Original file line number Diff line number Diff line change @@ -2876,7 +2876,7 @@ fn parse_alter_table_with_algorithm() {
2876
2876
vec![
2877
2877
AlterTableOperation :: DropColumn {
2878
2878
has_column_keyword: true ,
2879
- column_name : Ident :: new( "password_digest" ) ,
2879
+ column_names : vec! [ Ident :: new( "password_digest" ) ] ,
2880
2880
if_exists: false ,
2881
2881
drop_behavior: None ,
2882
2882
} ,
@@ -2924,7 +2924,7 @@ fn parse_alter_table_with_lock() {
2924
2924
vec![
2925
2925
AlterTableOperation :: DropColumn {
2926
2926
has_column_keyword: true ,
2927
- column_name : Ident :: new( "password_digest" ) ,
2927
+ column_names : vec! [ Ident :: new( "password_digest" ) ] ,
2928
2928
if_exists: false ,
2929
2929
drop_behavior: None ,
2930
2930
} ,
You can’t perform that action at this time.
0 commit comments