New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support DROP FUNCTION
syntax
#752
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1247,6 +1247,14 @@ pub enum Statement { | |
/// deleted along with the dropped table | ||
purge: bool, | ||
}, | ||
/// DROP Function | ||
DropFunction { | ||
if_exists: bool, | ||
/// One or more function to drop | ||
func_desc: Vec<DropFunctionDesc>, | ||
/// `CASCADE` or `RESTRICT` | ||
option: Option<DropFunctionOption>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will change it later, thanks for your suggestion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||
}, | ||
/// DECLARE - Declaring Cursor Variables | ||
/// | ||
/// Note: this is a PostgreSQL-specific statement, | ||
|
@@ -1411,7 +1419,7 @@ pub enum Statement { | |
or_replace: bool, | ||
temporary: bool, | ||
name: ObjectName, | ||
args: Option<Vec<CreateFunctionArg>>, | ||
args: Option<Vec<OperateFunctionArg>>, | ||
return_type: Option<DataType>, | ||
/// Optional parameters. | ||
params: CreateFunctionBody, | ||
|
@@ -2263,6 +2271,22 @@ impl fmt::Display for Statement { | |
if *restrict { " RESTRICT" } else { "" }, | ||
if *purge { " PURGE" } else { "" } | ||
), | ||
Statement::DropFunction { | ||
if_exists, | ||
func_desc, | ||
option, | ||
} => { | ||
write!( | ||
f, | ||
"DROP FUNCTION{} {}", | ||
if *if_exists { " IF EXISTS" } else { "" }, | ||
display_comma_separated(func_desc), | ||
)?; | ||
if let Some(op) = option { | ||
write!(f, " {}", op)?; | ||
} | ||
Ok(()) | ||
} | ||
Statement::Discard { object_type } => { | ||
write!(f, "DISCARD {object_type}", object_type = object_type)?; | ||
Ok(()) | ||
|
@@ -3691,17 +3715,52 @@ impl fmt::Display for ContextModifier { | |
} | ||
} | ||
|
||
/// Function argument in CREATE FUNCTION. | ||
/// Function describe in DROP FUNCTION. | ||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub enum DropFunctionOption { | ||
Restrict, | ||
Cascade, | ||
} | ||
|
||
impl fmt::Display for DropFunctionOption { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
DropFunctionOption::Restrict => write!(f, "RESTRICT "), | ||
DropFunctionOption::Cascade => write!(f, "CASCADE "), | ||
} | ||
} | ||
} | ||
|
||
/// Function describe in DROP FUNCTION. | ||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub struct DropFunctionDesc { | ||
pub name: ObjectName, | ||
pub args: Option<Vec<OperateFunctionArg>>, | ||
} | ||
|
||
impl fmt::Display for DropFunctionDesc { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.name)?; | ||
if let Some(args) = &self.args { | ||
write!(f, "({})", display_comma_separated(args))?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Function argument in CREATE OR DROP FUNCTION. | ||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub struct CreateFunctionArg { | ||
pub struct OperateFunctionArg { | ||
pub mode: Option<ArgMode>, | ||
pub name: Option<Ident>, | ||
pub data_type: DataType, | ||
pub default_expr: Option<Expr>, | ||
} | ||
|
||
impl CreateFunctionArg { | ||
impl OperateFunctionArg { | ||
/// Returns an unnamed argument. | ||
pub fn unnamed(data_type: DataType) -> Self { | ||
Self { | ||
|
@@ -3723,7 +3782,7 @@ impl CreateFunctionArg { | |
} | ||
} | ||
|
||
impl fmt::Display for CreateFunctionArg { | ||
impl fmt::Display for OperateFunctionArg { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
if let Some(mode) = &self.mode { | ||
write!(f, "{} ", mode)?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about reusing the
CreateFunctionArg
structure used in CREATE FUNCTIONsqlparser-rs/src/ast/mod.rs
Lines 1410 to 1417 in d420001
?
I can also see the argument for using a separate struct. If we stay with a separate struct, I suggest we name if
DropFunctionArg
to mirror theCreateFunctionArg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to combine these structures later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for my late reply。I've reconsidered your suggestion, and I think the structure might be acceptable. The
DropFunctionDesc
contains the function name and function parameters. TheCreateFunctionArg
only describes function parameters. Also,CreateFunctionArg
has been reused and renamedOperateFunctionArg