mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-04 13:10:31 +00:00
Support DROP FUNCTION
syntax (#752)
* drop function * update and to Option * fix review * update * fmt
This commit is contained in:
parent
3d5cc54dcf
commit
2d801c9fb6
3 changed files with 207 additions and 15 deletions
|
@ -2343,7 +2343,13 @@ impl<'a> Parser<'a> {
|
|||
} else if dialect_of!(self is PostgreSqlDialect) {
|
||||
let name = self.parse_object_name()?;
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let args = self.parse_comma_separated(Parser::parse_create_function_arg)?;
|
||||
let args = if self.consume_token(&Token::RParen) {
|
||||
self.prev_token();
|
||||
None
|
||||
} else {
|
||||
Some(self.parse_comma_separated(Parser::parse_function_arg)?)
|
||||
};
|
||||
|
||||
self.expect_token(&Token::RParen)?;
|
||||
|
||||
let return_type = if self.parse_keyword(Keyword::RETURNS) {
|
||||
|
@ -2358,7 +2364,7 @@ impl<'a> Parser<'a> {
|
|||
or_replace,
|
||||
temporary,
|
||||
name,
|
||||
args: Some(args),
|
||||
args,
|
||||
return_type,
|
||||
params,
|
||||
})
|
||||
|
@ -2368,7 +2374,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_create_function_arg(&mut self) -> Result<CreateFunctionArg, ParserError> {
|
||||
fn parse_function_arg(&mut self) -> Result<OperateFunctionArg, ParserError> {
|
||||
let mode = if self.parse_keyword(Keyword::IN) {
|
||||
Some(ArgMode::In)
|
||||
} else if self.parse_keyword(Keyword::OUT) {
|
||||
|
@ -2394,7 +2400,7 @@ impl<'a> Parser<'a> {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
Ok(CreateFunctionArg {
|
||||
Ok(OperateFunctionArg {
|
||||
mode,
|
||||
name,
|
||||
data_type,
|
||||
|
@ -2767,9 +2773,11 @@ impl<'a> Parser<'a> {
|
|||
ObjectType::Schema
|
||||
} else if self.parse_keyword(Keyword::SEQUENCE) {
|
||||
ObjectType::Sequence
|
||||
} else if self.parse_keyword(Keyword::FUNCTION) {
|
||||
return self.parse_drop_function();
|
||||
} else {
|
||||
return self.expected(
|
||||
"TABLE, VIEW, INDEX, ROLE, SCHEMA, or SEQUENCE after DROP",
|
||||
"TABLE, VIEW, INDEX, ROLE, SCHEMA, FUNCTION or SEQUENCE after DROP",
|
||||
self.peek_token(),
|
||||
);
|
||||
};
|
||||
|
@ -2796,6 +2804,41 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
/// DROP FUNCTION [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
|
||||
/// [ CASCADE | RESTRICT ]
|
||||
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_drop_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,
|
||||
};
|
||||
Ok(Statement::DropFunction {
|
||||
if_exists,
|
||||
func_desc,
|
||||
option,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_drop_function_desc(&mut self) -> Result<DropFunctionDesc, ParserError> {
|
||||
let name = self.parse_object_name()?;
|
||||
|
||||
let args = if self.consume_token(&Token::LParen) {
|
||||
if self.consume_token(&Token::RParen) {
|
||||
None
|
||||
} else {
|
||||
let args = self.parse_comma_separated(Parser::parse_function_arg)?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Some(args)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(DropFunctionDesc { name, args })
|
||||
}
|
||||
|
||||
/// DECLARE name [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ]
|
||||
// CURSOR [ { WITH | WITHOUT } HOLD ] FOR query
|
||||
pub fn parse_declare(&mut self) -> Result<Statement, ParserError> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue