@@ -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 , StorageSerializationPolicy , TableVersion , Tag , TriggerEvent ,
52- TriggerExecBody , TriggerObject , TriggerPeriod , TriggerReferencing , Value , ValueWithSpan ,
53- WrappedCollection ,
50+ OrderByExpr , ProjectionSelect , Query , RefreshModeKind , ResetConfig , RowAccessPolicy ,
51+ SequenceOptions , Spanned , SqlOption , StorageSerializationPolicy , TableVersion , Tag ,
52+ TriggerEvent , TriggerExecBody , TriggerObject , TriggerPeriod , TriggerReferencing , Value ,
53+ ValueWithSpan , WrappedCollection ,
5454} ;
5555use crate :: display_utils:: { DisplayCommaSeparated , Indent , NewLine , SpaceOrNewline } ;
5656use crate :: keywords:: Keyword ;
@@ -5121,6 +5121,214 @@ impl Spanned for AlterOperatorClass {
51215121 }
51225122}
51235123
5124+ /// `ALTER FUNCTION` / `ALTER AGGREGATE` statement.
5125+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5126+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5127+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5128+ pub struct AlterFunction {
5129+ /// Object type being altered.
5130+ pub kind : AlterFunctionKind ,
5131+ /// Function or aggregate signature.
5132+ pub function : FunctionDesc ,
5133+ /// `ORDER BY` argument list for aggregate signatures.
5134+ ///
5135+ /// This is only used for `ALTER AGGREGATE`.
5136+ pub aggregate_order_by : Option < Vec < OperateFunctionArg > > ,
5137+ /// Whether the aggregate signature uses `*`.
5138+ ///
5139+ /// This is only used for `ALTER AGGREGATE`.
5140+ pub aggregate_star : bool ,
5141+ /// Operation applied to the object.
5142+ pub operation : AlterFunctionOperation ,
5143+ }
5144+
5145+ /// Function-like object type used by [`AlterFunction`].
5146+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5147+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5148+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5149+ pub enum AlterFunctionKind {
5150+ /// `FUNCTION`
5151+ Function ,
5152+ /// `AGGREGATE`
5153+ Aggregate ,
5154+ }
5155+
5156+ impl fmt:: Display for AlterFunctionKind {
5157+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5158+ match self {
5159+ Self :: Function => write ! ( f, "FUNCTION" ) ,
5160+ Self :: Aggregate => write ! ( f, "AGGREGATE" ) ,
5161+ }
5162+ }
5163+ }
5164+
5165+ /// Operation for `ALTER FUNCTION` / `ALTER AGGREGATE`.
5166+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5167+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5168+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5169+ pub enum AlterFunctionOperation {
5170+ /// `RENAME TO new_name`
5171+ RenameTo {
5172+ /// New unqualified function or aggregate name.
5173+ new_name : Ident ,
5174+ } ,
5175+ /// `OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }`
5176+ OwnerTo ( Owner ) ,
5177+ /// `SET SCHEMA schema_name`
5178+ SetSchema {
5179+ /// The target schema name.
5180+ schema_name : ObjectName ,
5181+ } ,
5182+ /// `[ NO ] DEPENDS ON EXTENSION extension_name`
5183+ DependsOnExtension {
5184+ /// `true` when `NO DEPENDS ON EXTENSION`.
5185+ no : bool ,
5186+ /// Extension name.
5187+ extension_name : ObjectName ,
5188+ } ,
5189+ /// `action [ ... ] [ RESTRICT ]` (function only).
5190+ Actions {
5191+ /// One or more function actions.
5192+ actions : Vec < AlterFunctionAction > ,
5193+ /// Whether `RESTRICT` is present.
5194+ restrict : bool ,
5195+ } ,
5196+ }
5197+
5198+ /// Function action in `ALTER FUNCTION ... action [ ... ] [ RESTRICT ]`.
5199+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5200+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5201+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5202+ pub enum AlterFunctionAction {
5203+ /// `CALLED ON NULL INPUT` / `RETURNS NULL ON NULL INPUT` / `STRICT`
5204+ CalledOnNull ( FunctionCalledOnNull ) ,
5205+ /// `IMMUTABLE` / `STABLE` / `VOLATILE`
5206+ Behavior ( FunctionBehavior ) ,
5207+ /// `[ NOT ] LEAKPROOF`
5208+ Leakproof ( bool ) ,
5209+ /// `[ EXTERNAL ] SECURITY { DEFINER | INVOKER }`
5210+ Security {
5211+ /// Whether the optional `EXTERNAL` keyword was present.
5212+ external : bool ,
5213+ /// Security mode.
5214+ security : FunctionSecurity ,
5215+ } ,
5216+ /// `PARALLEL { UNSAFE | RESTRICTED | SAFE }`
5217+ Parallel ( FunctionParallel ) ,
5218+ /// `COST execution_cost`
5219+ Cost ( Expr ) ,
5220+ /// `ROWS result_rows`
5221+ Rows ( Expr ) ,
5222+ /// `SUPPORT support_function`
5223+ Support ( ObjectName ) ,
5224+ /// `SET configuration_parameter { TO | = } { value | DEFAULT }`
5225+ /// or `SET configuration_parameter FROM CURRENT`
5226+ Set ( FunctionDefinitionSetParam ) ,
5227+ /// `RESET configuration_parameter` or `RESET ALL`
5228+ Reset ( ResetConfig ) ,
5229+ }
5230+
5231+ impl fmt:: Display for AlterFunction {
5232+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5233+ write ! ( f, "ALTER {} " , self . kind) ?;
5234+ match self . kind {
5235+ AlterFunctionKind :: Function => {
5236+ write ! ( f, "{} " , self . function) ?;
5237+ }
5238+ AlterFunctionKind :: Aggregate => {
5239+ write ! ( f, "{}(" , self . function. name) ?;
5240+ if self . aggregate_star {
5241+ write ! ( f, "*" ) ?;
5242+ } else {
5243+ if let Some ( args) = & self . function . args {
5244+ write ! ( f, "{}" , display_comma_separated( args) ) ?;
5245+ }
5246+ if let Some ( order_by_args) = & self . aggregate_order_by {
5247+ if self
5248+ . function
5249+ . args
5250+ . as_ref ( )
5251+ . is_some_and ( |args| !args. is_empty ( ) )
5252+ {
5253+ write ! ( f, " " ) ?;
5254+ }
5255+ write ! ( f, "ORDER BY {}" , display_comma_separated( order_by_args) ) ?;
5256+ }
5257+ }
5258+ write ! ( f, ") " ) ?;
5259+ }
5260+ }
5261+ write ! ( f, "{}" , self . operation)
5262+ }
5263+ }
5264+
5265+ impl fmt:: Display for AlterFunctionOperation {
5266+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5267+ match self {
5268+ AlterFunctionOperation :: RenameTo { new_name } => {
5269+ write ! ( f, "RENAME TO {new_name}" )
5270+ }
5271+ AlterFunctionOperation :: OwnerTo ( owner) => write ! ( f, "OWNER TO {owner}" ) ,
5272+ AlterFunctionOperation :: SetSchema { schema_name } => {
5273+ write ! ( f, "SET SCHEMA {schema_name}" )
5274+ }
5275+ AlterFunctionOperation :: DependsOnExtension { no, extension_name } => {
5276+ if * no {
5277+ write ! ( f, "NO DEPENDS ON EXTENSION {extension_name}" )
5278+ } else {
5279+ write ! ( f, "DEPENDS ON EXTENSION {extension_name}" )
5280+ }
5281+ }
5282+ AlterFunctionOperation :: Actions { actions, restrict } => {
5283+ write ! ( f, "{}" , display_separated( actions, " " ) ) ?;
5284+ if * restrict {
5285+ write ! ( f, " RESTRICT" ) ?;
5286+ }
5287+ Ok ( ( ) )
5288+ }
5289+ }
5290+ }
5291+ }
5292+
5293+ impl fmt:: Display for AlterFunctionAction {
5294+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5295+ match self {
5296+ AlterFunctionAction :: CalledOnNull ( called_on_null) => write ! ( f, "{called_on_null}" ) ,
5297+ AlterFunctionAction :: Behavior ( behavior) => write ! ( f, "{behavior}" ) ,
5298+ AlterFunctionAction :: Leakproof ( leakproof) => {
5299+ if * leakproof {
5300+ write ! ( f, "LEAKPROOF" )
5301+ } else {
5302+ write ! ( f, "NOT LEAKPROOF" )
5303+ }
5304+ }
5305+ AlterFunctionAction :: Security { external, security } => {
5306+ if * external {
5307+ write ! ( f, "EXTERNAL " ) ?;
5308+ }
5309+ write ! ( f, "{security}" )
5310+ }
5311+ AlterFunctionAction :: Parallel ( parallel) => write ! ( f, "{parallel}" ) ,
5312+ AlterFunctionAction :: Cost ( execution_cost) => write ! ( f, "COST {execution_cost}" ) ,
5313+ AlterFunctionAction :: Rows ( result_rows) => write ! ( f, "ROWS {result_rows}" ) ,
5314+ AlterFunctionAction :: Support ( support_function) => {
5315+ write ! ( f, "SUPPORT {support_function}" )
5316+ }
5317+ AlterFunctionAction :: Set ( set_param) => write ! ( f, "{set_param}" ) ,
5318+ AlterFunctionAction :: Reset ( reset_config) => match reset_config {
5319+ ResetConfig :: ALL => write ! ( f, "RESET ALL" ) ,
5320+ ResetConfig :: ConfigName ( name) => write ! ( f, "RESET {name}" ) ,
5321+ } ,
5322+ }
5323+ }
5324+ }
5325+
5326+ impl Spanned for AlterFunction {
5327+ fn span ( & self ) -> Span {
5328+ Span :: empty ( )
5329+ }
5330+ }
5331+
51245332/// CREATE POLICY statement.
51255333///
51265334/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createpolicy.html)
0 commit comments