File tree 3 files changed +22
-0
lines changed 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ pub enum AlterTableOperation {
44
44
if_exists : bool ,
45
45
cascade : bool ,
46
46
} ,
47
+ /// `DROP PRIMARY KEY`
48
+ ///
49
+ /// Note: this is a MySQL-specific operation.
50
+ DropPrimaryKey ,
47
51
/// `RENAME TO PARTITION (partition=val)`
48
52
RenamePartitions {
49
53
old_partitions : Vec < Expr > ,
@@ -124,6 +128,7 @@ impl fmt::Display for AlterTableOperation {
124
128
if * cascade { " CASCADE" } else { "" } ,
125
129
)
126
130
}
131
+ AlterTableOperation :: DropPrimaryKey => write ! ( f, "DROP PRIMARY KEY" ) ,
127
132
AlterTableOperation :: DropColumn {
128
133
column_name,
129
134
if_exists,
Original file line number Diff line number Diff line change @@ -3137,6 +3137,10 @@ impl<'a> Parser<'a> {
3137
3137
name,
3138
3138
cascade,
3139
3139
}
3140
+ } else if self . parse_keywords ( & [ Keyword :: PRIMARY , Keyword :: KEY ] )
3141
+ && dialect_of ! ( self is MySqlDialect | GenericDialect )
3142
+ {
3143
+ AlterTableOperation :: DropPrimaryKey
3140
3144
} else {
3141
3145
let _ = self . parse_keyword ( Keyword :: COLUMN ) ;
3142
3146
let if_exists = self . parse_keywords ( & [ Keyword :: IF , Keyword :: EXISTS ] ) ;
Original file line number Diff line number Diff line change @@ -875,6 +875,19 @@ fn parse_update_with_joins() {
875
875
}
876
876
}
877
877
878
+ #[ test]
879
+ fn parse_alter_table_drop_primary_key ( ) {
880
+ match mysql_and_generic ( ) . verified_stmt ( "ALTER TABLE tab DROP PRIMARY KEY" ) {
881
+ Statement :: AlterTable {
882
+ name,
883
+ operation : AlterTableOperation :: DropPrimaryKey ,
884
+ } => {
885
+ assert_eq ! ( "tab" , name. to_string( ) ) ;
886
+ }
887
+ _ => unreachable ! ( ) ,
888
+ }
889
+ }
890
+
878
891
#[ test]
879
892
fn parse_alter_table_change_column ( ) {
880
893
let expected_name = ObjectName ( vec ! [ Ident :: new( "orders" ) ] ) ;
You can’t perform that action at this time.
0 commit comments