mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
Implements DROP POLICY syntax for PostgreSQL (#1445)
This commit is contained in:
parent
08fc6d3813
commit
2af981e4e6
3 changed files with 98 additions and 11 deletions
|
|
@ -4887,6 +4887,8 @@ impl<'a> Parser<'a> {
|
|||
ObjectType::Stage
|
||||
} else if self.parse_keyword(Keyword::FUNCTION) {
|
||||
return self.parse_drop_function();
|
||||
} else if self.parse_keyword(Keyword::POLICY) {
|
||||
return self.parse_drop_policy();
|
||||
} else if self.parse_keyword(Keyword::PROCEDURE) {
|
||||
return self.parse_drop_procedure();
|
||||
} else if self.parse_keyword(Keyword::SECRET) {
|
||||
|
|
@ -4928,6 +4930,14 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn parse_optional_referential_action(&mut self) -> Option<ReferentialAction> {
|
||||
match self.parse_one_of_keywords(&[Keyword::CASCADE, Keyword::RESTRICT]) {
|
||||
Some(Keyword::CASCADE) => Some(ReferentialAction::Cascade),
|
||||
Some(Keyword::RESTRICT) => Some(ReferentialAction::Restrict),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// ```sql
|
||||
/// DROP FUNCTION [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
|
||||
/// [ CASCADE | RESTRICT ]
|
||||
|
|
@ -4935,11 +4945,7 @@ impl<'a> Parser<'a> {
|
|||
fn parse_drop_function(&mut self) -> Result<Statement, ParserError> {
|
||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||
let func_desc = self.parse_comma_separated(Parser::parse_function_desc)?;
|
||||
let option = match self.parse_one_of_keywords(&[Keyword::CASCADE, Keyword::RESTRICT]) {
|
||||
Some(Keyword::CASCADE) => Some(ReferentialAction::Cascade),
|
||||
Some(Keyword::RESTRICT) => Some(ReferentialAction::Restrict),
|
||||
_ => None,
|
||||
};
|
||||
let option = self.parse_optional_referential_action();
|
||||
Ok(Statement::DropFunction {
|
||||
if_exists,
|
||||
func_desc,
|
||||
|
|
@ -4947,6 +4953,25 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
/// ```sql
|
||||
/// DROP POLICY [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ]
|
||||
/// ```
|
||||
///
|
||||
/// [PostgreSQL Documentation](https://www.postgresql.org/docs/current/sql-droppolicy.html)
|
||||
fn parse_drop_policy(&mut self) -> Result<Statement, ParserError> {
|
||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||
let name = self.parse_identifier(false)?;
|
||||
self.expect_keyword(Keyword::ON)?;
|
||||
let table_name = self.parse_object_name(false)?;
|
||||
let option = self.parse_optional_referential_action();
|
||||
Ok(Statement::DropPolicy {
|
||||
if_exists,
|
||||
name,
|
||||
table_name,
|
||||
option,
|
||||
})
|
||||
}
|
||||
|
||||
/// ```sql
|
||||
/// DROP PROCEDURE [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
|
||||
/// [ CASCADE | RESTRICT ]
|
||||
|
|
@ -4954,12 +4979,7 @@ impl<'a> Parser<'a> {
|
|||
fn parse_drop_procedure(&mut self) -> Result<Statement, ParserError> {
|
||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||
let proc_desc = self.parse_comma_separated(Parser::parse_function_desc)?;
|
||||
let option = match self.parse_one_of_keywords(&[Keyword::CASCADE, Keyword::RESTRICT]) {
|
||||
Some(Keyword::CASCADE) => Some(ReferentialAction::Cascade),
|
||||
Some(Keyword::RESTRICT) => Some(ReferentialAction::Restrict),
|
||||
Some(_) => unreachable!(), // parse_one_of_keywords does not return other keywords
|
||||
None => None,
|
||||
};
|
||||
let option = self.parse_optional_referential_action();
|
||||
Ok(Statement::DropProcedure {
|
||||
if_exists,
|
||||
proc_desc,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue