@@ -47,10 +47,10 @@ use crate::ast::{
4747 FunctionDeterminismSpecifier , FunctionParallel , FunctionSecurity , HiveDistributionStyle ,
4848 HiveFormat , HiveIOFormat , HiveRowFormat , HiveSetLocation , Ident , InitializeKind ,
4949 MySQLColumnPosition , ObjectName , OnCommit , OneOrManyWithParens , OperateFunctionArg ,
50- OrderByExpr , ProjectionSelect , Query , RefreshModeKind , RowAccessPolicy , SequenceOptions ,
51- Spanned , SqlOption , StorageLifecyclePolicy , StorageSerializationPolicy , TableVersion , Tag ,
52- TriggerEvent , TriggerExecBody , TriggerObject , TriggerPeriod , TriggerReferencing , Value ,
53- ValueWithSpan , WrappedCollection ,
50+ OrderByExpr , ProjectionSelect , Query , RefreshModeKind , ResetConfig , RowAccessPolicy ,
51+ SequenceOptions , Spanned , SqlOption , StorageLifecyclePolicy , StorageSerializationPolicy ,
52+ TableVersion , Tag , TriggerEvent , TriggerExecBody , TriggerObject , TriggerPeriod ,
53+ TriggerReferencing , Value , ValueWithSpan , WrappedCollection ,
5454} ;
5555use crate :: display_utils:: { DisplayCommaSeparated , Indent , NewLine , SpaceOrNewline } ;
5656use crate :: keywords:: Keyword ;
@@ -5222,6 +5222,214 @@ impl Spanned for AlterOperatorClass {
52225222 }
52235223}
52245224
5225+ /// `ALTER FUNCTION` / `ALTER AGGREGATE` statement.
5226+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5227+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5228+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5229+ pub struct AlterFunction {
5230+ /// Object type being altered.
5231+ pub kind : AlterFunctionKind ,
5232+ /// Function or aggregate signature.
5233+ pub function : FunctionDesc ,
5234+ /// `ORDER BY` argument list for aggregate signatures.
5235+ ///
5236+ /// This is only used for `ALTER AGGREGATE`.
5237+ pub aggregate_order_by : Option < Vec < OperateFunctionArg > > ,
5238+ /// Whether the aggregate signature uses `*`.
5239+ ///
5240+ /// This is only used for `ALTER AGGREGATE`.
5241+ pub aggregate_star : bool ,
5242+ /// Operation applied to the object.
5243+ pub operation : AlterFunctionOperation ,
5244+ }
5245+
5246+ /// Function-like object type used by [`AlterFunction`].
5247+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5248+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5249+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5250+ pub enum AlterFunctionKind {
5251+ /// `FUNCTION`
5252+ Function ,
5253+ /// `AGGREGATE`
5254+ Aggregate ,
5255+ }
5256+
5257+ impl fmt:: Display for AlterFunctionKind {
5258+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5259+ match self {
5260+ Self :: Function => write ! ( f, "FUNCTION" ) ,
5261+ Self :: Aggregate => write ! ( f, "AGGREGATE" ) ,
5262+ }
5263+ }
5264+ }
5265+
5266+ /// Operation for `ALTER FUNCTION` / `ALTER AGGREGATE`.
5267+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5268+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5269+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5270+ pub enum AlterFunctionOperation {
5271+ /// `RENAME TO new_name`
5272+ RenameTo {
5273+ /// New unqualified function or aggregate name.
5274+ new_name : Ident ,
5275+ } ,
5276+ /// `OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }`
5277+ OwnerTo ( Owner ) ,
5278+ /// `SET SCHEMA schema_name`
5279+ SetSchema {
5280+ /// The target schema name.
5281+ schema_name : ObjectName ,
5282+ } ,
5283+ /// `[ NO ] DEPENDS ON EXTENSION extension_name`
5284+ DependsOnExtension {
5285+ /// `true` when `NO DEPENDS ON EXTENSION`.
5286+ no : bool ,
5287+ /// Extension name.
5288+ extension_name : ObjectName ,
5289+ } ,
5290+ /// `action [ ... ] [ RESTRICT ]` (function only).
5291+ Actions {
5292+ /// One or more function actions.
5293+ actions : Vec < AlterFunctionAction > ,
5294+ /// Whether `RESTRICT` is present.
5295+ restrict : bool ,
5296+ } ,
5297+ }
5298+
5299+ /// Function action in `ALTER FUNCTION ... action [ ... ] [ RESTRICT ]`.
5300+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5301+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5302+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5303+ pub enum AlterFunctionAction {
5304+ /// `CALLED ON NULL INPUT` / `RETURNS NULL ON NULL INPUT` / `STRICT`
5305+ CalledOnNull ( FunctionCalledOnNull ) ,
5306+ /// `IMMUTABLE` / `STABLE` / `VOLATILE`
5307+ Behavior ( FunctionBehavior ) ,
5308+ /// `[ NOT ] LEAKPROOF`
5309+ Leakproof ( bool ) ,
5310+ /// `[ EXTERNAL ] SECURITY { DEFINER | INVOKER }`
5311+ Security {
5312+ /// Whether the optional `EXTERNAL` keyword was present.
5313+ external : bool ,
5314+ /// Security mode.
5315+ security : FunctionSecurity ,
5316+ } ,
5317+ /// `PARALLEL { UNSAFE | RESTRICTED | SAFE }`
5318+ Parallel ( FunctionParallel ) ,
5319+ /// `COST execution_cost`
5320+ Cost ( Expr ) ,
5321+ /// `ROWS result_rows`
5322+ Rows ( Expr ) ,
5323+ /// `SUPPORT support_function`
5324+ Support ( ObjectName ) ,
5325+ /// `SET configuration_parameter { TO | = } { value | DEFAULT }`
5326+ /// or `SET configuration_parameter FROM CURRENT`
5327+ Set ( FunctionDefinitionSetParam ) ,
5328+ /// `RESET configuration_parameter` or `RESET ALL`
5329+ Reset ( ResetConfig ) ,
5330+ }
5331+
5332+ impl fmt:: Display for AlterFunction {
5333+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5334+ write ! ( f, "ALTER {} " , self . kind) ?;
5335+ match self . kind {
5336+ AlterFunctionKind :: Function => {
5337+ write ! ( f, "{} " , self . function) ?;
5338+ }
5339+ AlterFunctionKind :: Aggregate => {
5340+ write ! ( f, "{}(" , self . function. name) ?;
5341+ if self . aggregate_star {
5342+ write ! ( f, "*" ) ?;
5343+ } else {
5344+ if let Some ( args) = & self . function . args {
5345+ write ! ( f, "{}" , display_comma_separated( args) ) ?;
5346+ }
5347+ if let Some ( order_by_args) = & self . aggregate_order_by {
5348+ if self
5349+ . function
5350+ . args
5351+ . as_ref ( )
5352+ . is_some_and ( |args| !args. is_empty ( ) )
5353+ {
5354+ write ! ( f, " " ) ?;
5355+ }
5356+ write ! ( f, "ORDER BY {}" , display_comma_separated( order_by_args) ) ?;
5357+ }
5358+ }
5359+ write ! ( f, ") " ) ?;
5360+ }
5361+ }
5362+ write ! ( f, "{}" , self . operation)
5363+ }
5364+ }
5365+
5366+ impl fmt:: Display for AlterFunctionOperation {
5367+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5368+ match self {
5369+ AlterFunctionOperation :: RenameTo { new_name } => {
5370+ write ! ( f, "RENAME TO {new_name}" )
5371+ }
5372+ AlterFunctionOperation :: OwnerTo ( owner) => write ! ( f, "OWNER TO {owner}" ) ,
5373+ AlterFunctionOperation :: SetSchema { schema_name } => {
5374+ write ! ( f, "SET SCHEMA {schema_name}" )
5375+ }
5376+ AlterFunctionOperation :: DependsOnExtension { no, extension_name } => {
5377+ if * no {
5378+ write ! ( f, "NO DEPENDS ON EXTENSION {extension_name}" )
5379+ } else {
5380+ write ! ( f, "DEPENDS ON EXTENSION {extension_name}" )
5381+ }
5382+ }
5383+ AlterFunctionOperation :: Actions { actions, restrict } => {
5384+ write ! ( f, "{}" , display_separated( actions, " " ) ) ?;
5385+ if * restrict {
5386+ write ! ( f, " RESTRICT" ) ?;
5387+ }
5388+ Ok ( ( ) )
5389+ }
5390+ }
5391+ }
5392+ }
5393+
5394+ impl fmt:: Display for AlterFunctionAction {
5395+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5396+ match self {
5397+ AlterFunctionAction :: CalledOnNull ( called_on_null) => write ! ( f, "{called_on_null}" ) ,
5398+ AlterFunctionAction :: Behavior ( behavior) => write ! ( f, "{behavior}" ) ,
5399+ AlterFunctionAction :: Leakproof ( leakproof) => {
5400+ if * leakproof {
5401+ write ! ( f, "LEAKPROOF" )
5402+ } else {
5403+ write ! ( f, "NOT LEAKPROOF" )
5404+ }
5405+ }
5406+ AlterFunctionAction :: Security { external, security } => {
5407+ if * external {
5408+ write ! ( f, "EXTERNAL " ) ?;
5409+ }
5410+ write ! ( f, "{security}" )
5411+ }
5412+ AlterFunctionAction :: Parallel ( parallel) => write ! ( f, "{parallel}" ) ,
5413+ AlterFunctionAction :: Cost ( execution_cost) => write ! ( f, "COST {execution_cost}" ) ,
5414+ AlterFunctionAction :: Rows ( result_rows) => write ! ( f, "ROWS {result_rows}" ) ,
5415+ AlterFunctionAction :: Support ( support_function) => {
5416+ write ! ( f, "SUPPORT {support_function}" )
5417+ }
5418+ AlterFunctionAction :: Set ( set_param) => write ! ( f, "{set_param}" ) ,
5419+ AlterFunctionAction :: Reset ( reset_config) => match reset_config {
5420+ ResetConfig :: ALL => write ! ( f, "RESET ALL" ) ,
5421+ ResetConfig :: ConfigName ( name) => write ! ( f, "RESET {name}" ) ,
5422+ } ,
5423+ }
5424+ }
5425+ }
5426+
5427+ impl Spanned for AlterFunction {
5428+ fn span ( & self ) -> Span {
5429+ Span :: empty ( )
5430+ }
5431+ }
5432+
52255433/// CREATE POLICY statement.
52265434///
52275435/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createpolicy.html)
0 commit comments