mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 15:39:12 +00:00
Parse MySQL ALTER TABLE DROP FOREIGN KEY
syntax (#1762)
This commit is contained in:
parent
6ec5223f50
commit
1e54a34acd
4 changed files with 27 additions and 4 deletions
|
@ -151,8 +151,18 @@ pub enum AlterTableOperation {
|
||||||
},
|
},
|
||||||
/// `DROP PRIMARY KEY`
|
/// `DROP PRIMARY KEY`
|
||||||
///
|
///
|
||||||
/// Note: this is a MySQL-specific operation.
|
/// Note: this is a [MySQL]-specific operation.
|
||||||
|
///
|
||||||
|
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
|
||||||
DropPrimaryKey,
|
DropPrimaryKey,
|
||||||
|
/// `DROP FOREIGN KEY <fk_symbol>`
|
||||||
|
///
|
||||||
|
/// Note: this is a [MySQL]-specific operation.
|
||||||
|
///
|
||||||
|
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
|
||||||
|
DropForeignKey {
|
||||||
|
name: Ident,
|
||||||
|
},
|
||||||
/// `ENABLE ALWAYS RULE rewrite_rule_name`
|
/// `ENABLE ALWAYS RULE rewrite_rule_name`
|
||||||
///
|
///
|
||||||
/// Note: this is a PostgreSQL-specific operation.
|
/// Note: this is a PostgreSQL-specific operation.
|
||||||
|
@ -530,6 +540,7 @@ impl fmt::Display for AlterTableOperation {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
AlterTableOperation::DropPrimaryKey => write!(f, "DROP PRIMARY KEY"),
|
AlterTableOperation::DropPrimaryKey => write!(f, "DROP PRIMARY KEY"),
|
||||||
|
AlterTableOperation::DropForeignKey { name } => write!(f, "DROP FOREIGN KEY {name}"),
|
||||||
AlterTableOperation::DropColumn {
|
AlterTableOperation::DropColumn {
|
||||||
column_name,
|
column_name,
|
||||||
if_exists,
|
if_exists,
|
||||||
|
|
|
@ -998,6 +998,7 @@ impl Spanned for AlterTableOperation {
|
||||||
.span()
|
.span()
|
||||||
.union_opt(&with_name.as_ref().map(|n| n.span)),
|
.union_opt(&with_name.as_ref().map(|n| n.span)),
|
||||||
AlterTableOperation::DropPrimaryKey => Span::empty(),
|
AlterTableOperation::DropPrimaryKey => Span::empty(),
|
||||||
|
AlterTableOperation::DropForeignKey { name } => name.span,
|
||||||
AlterTableOperation::EnableAlwaysRule { name } => name.span,
|
AlterTableOperation::EnableAlwaysRule { name } => name.span,
|
||||||
AlterTableOperation::EnableAlwaysTrigger { name } => name.span,
|
AlterTableOperation::EnableAlwaysTrigger { name } => name.span,
|
||||||
AlterTableOperation::EnableReplicaRule { name } => name.span,
|
AlterTableOperation::EnableReplicaRule { name } => name.span,
|
||||||
|
|
|
@ -7998,10 +7998,11 @@ impl<'a> Parser<'a> {
|
||||||
name,
|
name,
|
||||||
drop_behavior,
|
drop_behavior,
|
||||||
}
|
}
|
||||||
} else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY])
|
} else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY]) {
|
||||||
&& dialect_of!(self is MySqlDialect | GenericDialect)
|
|
||||||
{
|
|
||||||
AlterTableOperation::DropPrimaryKey
|
AlterTableOperation::DropPrimaryKey
|
||||||
|
} else if self.parse_keywords(&[Keyword::FOREIGN, Keyword::KEY]) {
|
||||||
|
let name = self.parse_identifier()?;
|
||||||
|
AlterTableOperation::DropForeignKey { name }
|
||||||
} else if self.parse_keyword(Keyword::PROJECTION)
|
} else if self.parse_keyword(Keyword::PROJECTION)
|
||||||
&& dialect_of!(self is ClickHouseDialect|GenericDialect)
|
&& dialect_of!(self is ClickHouseDialect|GenericDialect)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2273,6 +2273,16 @@ fn parse_alter_table_drop_primary_key() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_alter_table_drop_foreign_key() {
|
||||||
|
assert_matches!(
|
||||||
|
alter_table_op(
|
||||||
|
mysql_and_generic().verified_stmt("ALTER TABLE tab DROP FOREIGN KEY foo_ibfk_1")
|
||||||
|
),
|
||||||
|
AlterTableOperation::DropForeignKey { name } if name.value == "foo_ibfk_1"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_alter_table_change_column() {
|
fn parse_alter_table_change_column() {
|
||||||
let expected_name = ObjectName::from(vec![Ident::new("orders")]);
|
let expected_name = ObjectName::from(vec![Ident::new("orders")]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue