mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Add support for ALTER TABLE DROP INDEX
(#1865)
Some checks are pending
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
Some checks are pending
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
This commit is contained in:
parent
40d12b98bd
commit
559b7e36d9
4 changed files with 21 additions and 0 deletions
|
@ -187,6 +187,12 @@ pub enum AlterTableOperation {
|
||||||
DropForeignKey {
|
DropForeignKey {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
},
|
},
|
||||||
|
/// `DROP INDEX <index_name>`
|
||||||
|
///
|
||||||
|
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
|
||||||
|
DropIndex {
|
||||||
|
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.
|
||||||
|
@ -606,6 +612,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::DropForeignKey { name } => write!(f, "DROP FOREIGN KEY {name}"),
|
||||||
|
AlterTableOperation::DropIndex { name } => write!(f, "DROP INDEX {name}"),
|
||||||
AlterTableOperation::DropColumn {
|
AlterTableOperation::DropColumn {
|
||||||
has_column_keyword,
|
has_column_keyword,
|
||||||
column_name,
|
column_name,
|
||||||
|
|
|
@ -1115,6 +1115,7 @@ impl Spanned for AlterTableOperation {
|
||||||
.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::DropForeignKey { name } => name.span,
|
||||||
|
AlterTableOperation::DropIndex { 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,
|
||||||
|
|
|
@ -8636,6 +8636,9 @@ impl<'a> Parser<'a> {
|
||||||
} else if self.parse_keywords(&[Keyword::FOREIGN, Keyword::KEY]) {
|
} else if self.parse_keywords(&[Keyword::FOREIGN, Keyword::KEY]) {
|
||||||
let name = self.parse_identifier()?;
|
let name = self.parse_identifier()?;
|
||||||
AlterTableOperation::DropForeignKey { name }
|
AlterTableOperation::DropForeignKey { name }
|
||||||
|
} else if self.parse_keyword(Keyword::INDEX) {
|
||||||
|
let name = self.parse_identifier()?;
|
||||||
|
AlterTableOperation::DropIndex { 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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4025,3 +4025,13 @@ fn parse_drop_index() {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_alter_table_drop_index() {
|
||||||
|
assert_matches!(
|
||||||
|
alter_table_op(
|
||||||
|
mysql_and_generic().verified_stmt("ALTER TABLE tab DROP INDEX idx_index")
|
||||||
|
),
|
||||||
|
AlterTableOperation::DropIndex { name } if name.value == "idx_index"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue