File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ pub enum AlterTableOperation {
4444 if_exists : bool ,
4545 cascade : bool ,
4646 } ,
47+ /// `DROP PRIMARY KEY`
48+ ///
49+ /// Note: this is a MySQL-specific operation.
50+ DropPrimaryKey ,
4751 /// `RENAME TO PARTITION (partition=val)`
4852 RenamePartitions {
4953 old_partitions : Vec < Expr > ,
@@ -124,6 +128,7 @@ impl fmt::Display for AlterTableOperation {
124128 if * cascade { " CASCADE" } else { "" } ,
125129 )
126130 }
131+ AlterTableOperation :: DropPrimaryKey => write ! ( f, "DROP PRIMARY KEY" ) ,
127132 AlterTableOperation :: DropColumn {
128133 column_name,
129134 if_exists,
Original file line number Diff line number Diff line change @@ -3137,6 +3137,10 @@ impl<'a> Parser<'a> {
31373137 name,
31383138 cascade,
31393139 }
3140+ } else if self . parse_keywords ( & [ Keyword :: PRIMARY , Keyword :: KEY ] )
3141+ && dialect_of ! ( self is MySqlDialect | GenericDialect )
3142+ {
3143+ AlterTableOperation :: DropPrimaryKey
31403144 } else {
31413145 let _ = self . parse_keyword ( Keyword :: COLUMN ) ;
31423146 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() {
875875 }
876876}
877877
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+
878891#[ test]
879892fn parse_alter_table_change_column ( ) {
880893 let expected_name = ObjectName ( vec ! [ Ident :: new( "orders" ) ] ) ;
You can’t perform that action at this time.
0 commit comments