mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
Implement ALTER TABLE DROP COLUMN (#148)
This implements `DROP [ COLUMN ] [ IF EXISTS ] column_name [ CASCADE ]` sub-command of `ALTER TABLE`, which is what PostgreSQL supports https://www.postgresql.org/docs/12/sql-altertable.html (except for the RESTRICT option) Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
This commit is contained in:
parent
faeb7d440a
commit
26361fd854
4 changed files with 62 additions and 1 deletions
|
@ -1388,6 +1388,39 @@ fn parse_alter_table_constraints() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_alter_table_drop_column() {
|
||||
check_one("DROP COLUMN IF EXISTS is_active CASCADE");
|
||||
one_statement_parses_to(
|
||||
"ALTER TABLE tab DROP IF EXISTS is_active CASCADE",
|
||||
"ALTER TABLE tab DROP COLUMN IF EXISTS is_active CASCADE",
|
||||
);
|
||||
one_statement_parses_to(
|
||||
"ALTER TABLE tab DROP is_active CASCADE",
|
||||
"ALTER TABLE tab DROP COLUMN is_active CASCADE",
|
||||
);
|
||||
|
||||
fn check_one(constraint_text: &str) {
|
||||
match verified_stmt(&format!("ALTER TABLE tab {}", constraint_text)) {
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
operation:
|
||||
AlterTableOperation::DropColumn {
|
||||
column_name,
|
||||
if_exists,
|
||||
cascade,
|
||||
},
|
||||
} => {
|
||||
assert_eq!("tab", name.to_string());
|
||||
assert_eq!("is_active", column_name.to_string());
|
||||
assert_eq!(true, if_exists);
|
||||
assert_eq!(true, cascade);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_bad_constraint() {
|
||||
let res = parse_sql_statements("ALTER TABLE tab ADD");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue