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

@ -1340,8 +1340,18 @@ impl Parser {
new_column_name,
}
}
} else if self.parse_keyword(Keyword::DROP) {
let _ = self.parse_keyword(Keyword::COLUMN);
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let column_name = self.parse_identifier()?;
let cascade = self.parse_keyword(Keyword::CASCADE);
AlterTableOperation::DropColumn {
column_name,
if_exists,
cascade,
}
} else {
return self.expected("ADD or RENAME after ALTER TABLE", self.peek_token());
return self.expected("ADD, RENAME, or DROP after ALTER TABLE", self.peek_token());
};
Ok(Statement::AlterTable {
name: table_name,