mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-31 20:22:17 +00:00
Support ALTER TABLE DROP PRIMARY KEY
(#682)
* parse alter table drop primary key * cargo nightly fmt * add Dialect validation
This commit is contained in:
parent
1b3778e2d5
commit
27c3ec87db
3 changed files with 22 additions and 0 deletions
|
@ -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>,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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")]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue