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 @@ -140,10 +140,10 @@ pub enum AlterTableOperation {
140
140
name : Ident ,
141
141
drop_behavior : Option < DropBehavior > ,
142
142
} ,
143
- /// `DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ CASCADE ]`
143
+ /// `DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ , <column_name>, ... ] [ CASCADE ]`
144
144
DropColumn {
145
145
has_column_keyword : bool ,
146
- column_name : Ident ,
146
+ column_names : Vec < Ident > ,
147
147
if_exists : bool ,
148
148
drop_behavior : Option < DropBehavior > ,
149
149
} ,
@@ -631,15 +631,15 @@ impl fmt::Display for AlterTableOperation {
631
631
AlterTableOperation :: DropIndex { name } => write ! ( f, "DROP INDEX {name}" ) ,
632
632
AlterTableOperation :: DropColumn {
633
633
has_column_keyword,
634
- column_name,
634
+ column_names : column_name,
635
635
if_exists,
636
636
drop_behavior,
637
637
} => write ! (
638
638
f,
639
639
"DROP {}{}{}{}" ,
640
640
if * has_column_keyword { "COLUMN " } else { "" } ,
641
641
if * if_exists { "IF EXISTS " } else { "" } ,
642
- column_name,
642
+ display_comma_separated ( column_name) ,
643
643
match drop_behavior {
644
644
None => "" ,
645
645
Some ( DropBehavior :: Restrict ) => " RESTRICT" ,
Original file line number Diff line number Diff line change @@ -1112,10 +1112,10 @@ impl Spanned for AlterTableOperation {
1112
1112
} => name. span ,
1113
1113
AlterTableOperation :: DropColumn {
1114
1114
has_column_keyword : _,
1115
- column_name ,
1115
+ column_names ,
1116
1116
if_exists : _,
1117
1117
drop_behavior : _,
1118
- } => column_name . span ,
1118
+ } => union_spans ( column_names . iter ( ) . map ( |i| i . span ) ) ,
1119
1119
AlterTableOperation :: AttachPartition { partition } => partition. span ( ) ,
1120
1120
AlterTableOperation :: DetachPartition { partition } => partition. span ( ) ,
1121
1121
AlterTableOperation :: FreezePartition {
Original file line number Diff line number Diff line change @@ -1071,6 +1071,11 @@ pub trait Dialect: Debug + Any {
1071
1071
fn supports_alter_column_type_using ( & self ) -> bool {
1072
1072
false
1073
1073
}
1074
+
1075
+ /// Returns true if the dialect supports `ALTER TABLE tbl DROP COLUMN c1, ..., cn`
1076
+ fn supports_comma_separated_drop_column_list ( & self ) -> bool {
1077
+ false
1078
+ }
1074
1079
}
1075
1080
1076
1081
/// 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 @@ -8675,11 +8675,15 @@ impl<'a> Parser<'a> {
8675
8675
} else {
8676
8676
let has_column_keyword = self.parse_keyword(Keyword::COLUMN); // [ COLUMN ]
8677
8677
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
8678
- let column_name = self.parse_identifier()?;
8678
+ let column_names = if self.dialect.supports_comma_separated_drop_column_list() {
8679
+ self.parse_comma_separated(Parser::parse_identifier)?
8680
+ } else {
8681
+ vec![self.parse_identifier()?]
8682
+ };
8679
8683
let drop_behavior = self.parse_optional_drop_behavior();
8680
8684
AlterTableOperation::DropColumn {
8681
8685
has_column_keyword,
8682
- column_name ,
8686
+ column_names ,
8683
8687
if_exists,
8684
8688
drop_behavior,
8685
8689
}
Original file line number Diff line number Diff line change @@ -4996,15 +4996,18 @@ fn parse_alter_table_drop_column() {
4996
4996
"ALTER TABLE tab DROP is_active CASCADE",
4997
4997
);
4998
4998
4999
+ let dialects = all_dialects_where(|d| d.supports_comma_separated_drop_column_list());
5000
+ dialects.verified_stmt("ALTER TABLE tbl DROP COLUMN c1, c2, c3");
5001
+
4999
5002
fn check_one(constraint_text: &str) {
5000
5003
match alter_table_op(verified_stmt(&format!("ALTER TABLE tab {constraint_text}"))) {
5001
5004
AlterTableOperation::DropColumn {
5002
5005
has_column_keyword: true,
5003
- column_name ,
5006
+ column_names ,
5004
5007
if_exists,
5005
5008
drop_behavior,
5006
5009
} => {
5007
- assert_eq!("is_active", column_name .to_string());
5010
+ assert_eq!("is_active", column_names.first().unwrap() .to_string());
5008
5011
assert!(if_exists);
5009
5012
match drop_behavior {
5010
5013
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