Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3319,6 +3319,18 @@ pub enum Statement {
drop_behavior: Option<DropBehavior>,
},
/// ```sql
/// DROP DOMAIN
/// ```
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-dropdomain.html)
///
/// DROP DOMAIN [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
///
DropDomain {
if_exists: bool,
name: ObjectName,
drop_behavior: Option<DropBehavior>,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we wrap the new statement in a named struct? We're looking to move over to that pattern for newer statements. e.g.

struct DropDomain {
    if_exist: bool 
    // ...
}
Statement::DropDomain(DropDomain)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 10dab51

/// ```sql
/// DROP PROCEDURE
/// ```
DropProcedure {
Expand Down Expand Up @@ -5092,6 +5104,21 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::DropDomain {
if_exists,
name,
drop_behavior,
} => {
write!(
f,
"DROP DOMAIN{} {name}",
if *if_exists { " IF EXISTS" } else { "" },
)?;
if let Some(op) = drop_behavior {
write!(f, " {op}")?;
}
Ok(())
}
Statement::DropProcedure {
if_exists,
proc_desc,
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ impl Spanned for Statement {
Statement::DetachDuckDBDatabase { .. } => Span::empty(),
Statement::Drop { .. } => Span::empty(),
Statement::DropFunction { .. } => Span::empty(),
Statement::DropDomain { .. } => Span::empty(),
Statement::DropProcedure { .. } => Span::empty(),
Statement::DropSecret { .. } => Span::empty(),
Statement::Declare { .. } => Span::empty(),
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ define_keywords!(
DISTRIBUTE,
DIV,
DO,
DOMAIN,
DOUBLE,
DOW,
DOY,
Expand Down
16 changes: 16 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6051,6 +6051,8 @@ impl<'a> Parser<'a> {
return self.parse_drop_policy();
} else if self.parse_keyword(Keyword::CONNECTOR) {
return self.parse_drop_connector();
} else if self.parse_keyword(Keyword::DOMAIN) {
return self.parse_drop_domain();
} else if self.parse_keyword(Keyword::PROCEDURE) {
return self.parse_drop_procedure();
} else if self.parse_keyword(Keyword::SECRET) {
Expand Down Expand Up @@ -6146,6 +6148,20 @@ impl<'a> Parser<'a> {
Ok(Statement::DropConnector { if_exists, name })
}

/// ```sql
/// DROP DOMAIN [ IF EXISTS ] name [ CASCADE | RESTRICT ]
/// ```
fn parse_drop_domain(&mut self) -> Result<Statement, ParserError> {
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let name = self.parse_object_name(false)?;
let drop_behavior = self.parse_optional_drop_behavior();
Ok(Statement::DropDomain {
if_exists,
name,
drop_behavior,
})
}

/// ```sql
/// DROP PROCEDURE [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
/// [ CASCADE | RESTRICT ]
Expand Down
60 changes: 60 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4239,6 +4239,66 @@ fn parse_drop_function() {
);
}

#[test]
fn parse_drop_domain() {
let sql = "DROP DOMAIN IF EXISTS jpeg_domain";
assert_eq!(
pg().verified_stmt(sql),
Statement::DropDomain {
if_exists: true,
name: ObjectName::from(vec![Ident {
value: "jpeg_domain".to_string(),
quote_style: None,
span: Span::empty(),
}]),
drop_behavior: None
}
);

let sql = "DROP DOMAIN jpeg_domain";
assert_eq!(
pg().verified_stmt(sql),
Statement::DropDomain {
if_exists: false,
name: ObjectName::from(vec![Ident {
value: "jpeg_domain".to_string(),
quote_style: None,
span: Span::empty(),
}]),
drop_behavior: None
}
);

let sql = "DROP DOMAIN IF EXISTS jpeg_domain CASCADE";
assert_eq!(
pg().verified_stmt(sql),
Statement::DropDomain {
if_exists: true,
name: ObjectName::from(vec![Ident {
value: "jpeg_domain".to_string(),
quote_style: None,
span: Span::empty(),
}]),
drop_behavior: Some(DropBehavior::Cascade)
}
);

let sql = "DROP DOMAIN IF EXISTS jpeg_domain RESTRICT";

assert_eq!(
pg().verified_stmt(sql),
Statement::DropDomain {
if_exists: true,
name: ObjectName::from(vec![Ident {
value: "jpeg_domain".to_string(),
quote_style: None,
span: Span::empty(),
}]),
drop_behavior: Some(DropBehavior::Restrict)
}
);
}

#[test]
fn parse_drop_procedure() {
let sql = "DROP PROCEDURE IF EXISTS test_proc";
Expand Down