Skip to content

Commit

Permalink
Merge 11cab1f into 1b3778e
Browse files Browse the repository at this point in the history
  • Loading branch information
ding-young committed Oct 31, 2022
2 parents 1b3778e + 11cab1f commit 9a1d1f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub enum AlterTableOperation {
if_exists: bool,
cascade: bool,
},
/// `DROP PRIMARY KEY`
///
/// Note: this is a MySQL-specific operation.
DropPrimaryKey,
/// `RENAME TO PARTITION (partition=val)`
RenamePartitions {
old_partitions: Vec<Expr>,
Expand Down Expand Up @@ -124,6 +128,7 @@ impl fmt::Display for AlterTableOperation {
if *cascade { " CASCADE" } else { "" },
)
}
AlterTableOperation::DropPrimaryKey => write!(f, "DROP PRIMARY KEY"),
AlterTableOperation::DropColumn {
column_name,
if_exists,
Expand Down
4 changes: 4 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,10 @@ impl<'a> Parser<'a> {
name,
cascade,
}
} else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY])
&& dialect_of!(self is MySqlDialect | GenericDialect)
{
AlterTableOperation::DropPrimaryKey
} else {
let _ = self.parse_keyword(Keyword::COLUMN);
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,19 @@ fn parse_update_with_joins() {
}
}

#[test]
fn parse_alter_table_drop_primary_key() {
match mysql_and_generic().verified_stmt("ALTER TABLE tab DROP PRIMARY KEY") {
Statement::AlterTable {
name,
operation: AlterTableOperation::DropPrimaryKey,
} => {
assert_eq!("tab", name.to_string());
}
_ => unreachable!(),
}
}

#[test]
fn parse_alter_table_change_column() {
let expected_name = ObjectName(vec![Ident::new("orders")]);
Expand Down

0 comments on commit 9a1d1f0

Please sign in to comment.