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:
Jovansonlee Cesar 2020-06-17 04:39:52 +08:00 committed by GitHub
parent faeb7d440a
commit 26361fd854
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 1 deletions

View file

@ -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");