File tree 5 files changed +12
-4
lines changed 5 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ pub enum AlterTableOperation {
139
139
} ,
140
140
/// `DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ CASCADE ]`
141
141
DropColumn {
142
+ has_column_keyword : bool ,
142
143
column_name : Ident ,
143
144
if_exists : bool ,
144
145
drop_behavior : Option < DropBehavior > ,
@@ -606,12 +607,14 @@ impl fmt::Display for AlterTableOperation {
606
607
AlterTableOperation :: DropPrimaryKey => write ! ( f, "DROP PRIMARY KEY" ) ,
607
608
AlterTableOperation :: DropForeignKey { name } => write ! ( f, "DROP FOREIGN KEY {name}" ) ,
608
609
AlterTableOperation :: DropColumn {
610
+ has_column_keyword,
609
611
column_name,
610
612
if_exists,
611
613
drop_behavior,
612
614
} => write ! (
613
615
f,
614
- "DROP COLUMN {}{}{}" ,
616
+ "DROP {}{}{}{}" ,
617
+ if * has_column_keyword { "COLUMN " } else { "" } ,
615
618
if * if_exists { "IF EXISTS " } else { "" } ,
616
619
column_name,
617
620
match drop_behavior {
Original file line number Diff line number Diff line change @@ -1090,6 +1090,7 @@ impl Spanned for AlterTableOperation {
1090
1090
drop_behavior : _,
1091
1091
} => name. span ,
1092
1092
AlterTableOperation :: DropColumn {
1093
+ has_column_keyword : _,
1093
1094
column_name,
1094
1095
if_exists : _,
1095
1096
drop_behavior : _,
Original file line number Diff line number Diff line change @@ -8608,11 +8608,12 @@ impl<'a> Parser<'a> {
8608
8608
} else if self.parse_keywords(&[Keyword::CLUSTERING, Keyword::KEY]) {
8609
8609
AlterTableOperation::DropClusteringKey
8610
8610
} else {
8611
- let _ = self.parse_keyword(Keyword::COLUMN); // [ COLUMN ]
8611
+ let has_column_keyword = self.parse_keyword(Keyword::COLUMN); // [ COLUMN ]
8612
8612
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
8613
8613
let column_name = self.parse_identifier()?;
8614
8614
let drop_behavior = self.parse_optional_drop_behavior();
8615
8615
AlterTableOperation::DropColumn {
8616
+ has_column_keyword,
8616
8617
column_name,
8617
8618
if_exists,
8618
8619
drop_behavior,
Original file line number Diff line number Diff line change @@ -4926,17 +4926,18 @@ fn parse_alter_table_drop_column() {
4926
4926
check_one("DROP COLUMN IF EXISTS is_active CASCADE");
4927
4927
check_one("DROP COLUMN IF EXISTS is_active RESTRICT");
4928
4928
one_statement_parses_to(
4929
- "ALTER TABLE tab DROP IF EXISTS is_active CASCADE",
4929
+ "ALTER TABLE tab DROP COLUMN IF EXISTS is_active CASCADE",
4930
4930
"ALTER TABLE tab DROP COLUMN IF EXISTS is_active CASCADE",
4931
4931
);
4932
4932
one_statement_parses_to(
4933
4933
"ALTER TABLE tab DROP is_active CASCADE",
4934
- "ALTER TABLE tab DROP COLUMN is_active CASCADE",
4934
+ "ALTER TABLE tab DROP is_active CASCADE",
4935
4935
);
4936
4936
4937
4937
fn check_one(constraint_text: &str) {
4938
4938
match alter_table_op(verified_stmt(&format!("ALTER TABLE tab {constraint_text}"))) {
4939
4939
AlterTableOperation::DropColumn {
4940
+ has_column_keyword: true,
4940
4941
column_name,
4941
4942
if_exists,
4942
4943
drop_behavior,
Original file line number Diff line number Diff line change @@ -2801,6 +2801,7 @@ fn parse_alter_table_with_algorithm() {
2801
2801
operations,
2802
2802
vec![
2803
2803
AlterTableOperation :: DropColumn {
2804
+ has_column_keyword: true ,
2804
2805
column_name: Ident :: new( "password_digest" ) ,
2805
2806
if_exists: false ,
2806
2807
drop_behavior: None ,
@@ -2848,6 +2849,7 @@ fn parse_alter_table_with_lock() {
2848
2849
operations,
2849
2850
vec![
2850
2851
AlterTableOperation :: DropColumn {
2852
+ has_column_keyword: true ,
2851
2853
column_name: Ident :: new( "password_digest" ) ,
2852
2854
if_exists: false ,
2853
2855
drop_behavior: None ,
You can’t perform that action at this time.
0 commit comments