mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-11-11 19:43:47 +00:00
Support DROP CONSTRAINT [ IF EXISTS ] <name> [ CASCADE ] (#396)
* adding support for DROP CONSTRAINT [ IF EXISTS ] <name> * implementing [ CASCADE ] for DROP CONSTRAINT
This commit is contained in:
parent
e4959696b5
commit
c4cbc8340a
3 changed files with 76 additions and 3 deletions
|
|
@ -32,8 +32,12 @@ pub enum AlterTableOperation {
|
|||
AddConstraint(TableConstraint),
|
||||
/// `ADD [ COLUMN ] <column_def>`
|
||||
AddColumn { column_def: ColumnDef },
|
||||
/// TODO: implement `DROP CONSTRAINT <name>`
|
||||
DropConstraint { name: Ident },
|
||||
/// `DROP CONSTRAINT [ IF EXISTS ] <name>`
|
||||
DropConstraint {
|
||||
if_exists: bool,
|
||||
name: Ident,
|
||||
cascade: bool,
|
||||
},
|
||||
/// `DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ CASCADE ]`
|
||||
DropColumn {
|
||||
column_name: Ident,
|
||||
|
|
@ -107,7 +111,19 @@ impl fmt::Display for AlterTableOperation {
|
|||
display_comma_separated(partitions),
|
||||
ie = if *if_exists { " IF EXISTS" } else { "" }
|
||||
),
|
||||
AlterTableOperation::DropConstraint { name } => write!(f, "DROP CONSTRAINT {}", name),
|
||||
AlterTableOperation::DropConstraint {
|
||||
if_exists,
|
||||
name,
|
||||
cascade,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"DROP CONSTRAINT {}{}{}",
|
||||
if *if_exists { "IF EXISTS " } else { "" },
|
||||
name,
|
||||
if *cascade { " CASCADE" } else { "" },
|
||||
)
|
||||
}
|
||||
AlterTableOperation::DropColumn {
|
||||
column_name,
|
||||
if_exists,
|
||||
|
|
|
|||
|
|
@ -2030,6 +2030,15 @@ impl<'a> Parser<'a> {
|
|||
partitions,
|
||||
if_exists: false,
|
||||
}
|
||||
} else if self.parse_keyword(Keyword::CONSTRAINT) {
|
||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||
let name = self.parse_identifier()?;
|
||||
let cascade = self.parse_keyword(Keyword::CASCADE);
|
||||
AlterTableOperation::DropConstraint {
|
||||
if_exists,
|
||||
name,
|
||||
cascade,
|
||||
}
|
||||
} else {
|
||||
let _ = self.parse_keyword(Keyword::COLUMN);
|
||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue