@@ -5859,6 +5859,160 @@ impl From<CreateForeignTable> for crate::ast::Statement {
58595859 crate :: ast:: Statement :: CreateForeignTable ( v)
58605860 }
58615861}
5862+
5863+ /// CREATE AGGREGATE statement.
5864+ /// See <https://www.postgresql.org/docs/current/sql-createaggregate.html>
5865+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5866+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5867+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5868+ pub struct CreateAggregate {
5869+ /// True if `OR REPLACE` was specified.
5870+ pub or_replace : bool ,
5871+ /// The aggregate name (can be schema-qualified).
5872+ pub name : ObjectName ,
5873+ /// Input argument types. Empty for zero-argument aggregates.
5874+ pub args : Vec < DataType > ,
5875+ /// The options listed inside the required parentheses after the argument
5876+ /// list (e.g. `SFUNC`, `STYPE`, `FINALFUNC`, `PARALLEL`, …).
5877+ pub options : Vec < CreateAggregateOption > ,
5878+ }
5879+
5880+ impl fmt:: Display for CreateAggregate {
5881+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5882+ write ! ( f, "CREATE" ) ?;
5883+ if self . or_replace {
5884+ write ! ( f, " OR REPLACE" ) ?;
5885+ }
5886+ write ! ( f, " AGGREGATE {}" , self . name) ?;
5887+ write ! ( f, " ({})" , display_comma_separated( & self . args) ) ?;
5888+ write ! ( f, " (" ) ?;
5889+ for ( i, option) in self . options . iter ( ) . enumerate ( ) {
5890+ if i > 0 {
5891+ write ! ( f, ", " ) ?;
5892+ }
5893+ write ! ( f, "{option}" ) ?;
5894+ }
5895+ write ! ( f, ")" )
5896+ }
5897+ }
5898+
5899+ impl From < CreateAggregate > for crate :: ast:: Statement {
5900+ fn from ( v : CreateAggregate ) -> Self {
5901+ crate :: ast:: Statement :: CreateAggregate ( v)
5902+ }
5903+ }
5904+
5905+ /// A single option in a `CREATE AGGREGATE` options list.
5906+ ///
5907+ /// See <https://www.postgresql.org/docs/current/sql-createaggregate.html>
5908+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5909+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5910+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5911+ pub enum CreateAggregateOption {
5912+ /// `SFUNC = state_transition_function`
5913+ Sfunc ( ObjectName ) ,
5914+ /// `STYPE = state_data_type`
5915+ Stype ( DataType ) ,
5916+ /// `SSPACE = state_data_size` (in bytes)
5917+ Sspace ( u64 ) ,
5918+ /// `FINALFUNC = final_function`
5919+ Finalfunc ( ObjectName ) ,
5920+ /// `FINALFUNC_EXTRA` — pass extra dummy arguments to the final function.
5921+ FinalfuncExtra ,
5922+ /// `FINALFUNC_MODIFY = { READ_ONLY | SHAREABLE | READ_WRITE }`
5923+ FinalfuncModify ( AggregateModifyKind ) ,
5924+ /// `COMBINEFUNC = combine_function`
5925+ Combinefunc ( ObjectName ) ,
5926+ /// `SERIALFUNC = serial_function`
5927+ Serialfunc ( ObjectName ) ,
5928+ /// `DESERIALFUNC = deserial_function`
5929+ Deserialfunc ( ObjectName ) ,
5930+ /// `INITCOND = initial_condition` (a string literal)
5931+ Initcond ( Value ) ,
5932+ /// `MSFUNC = moving_state_transition_function`
5933+ Msfunc ( ObjectName ) ,
5934+ /// `MINVFUNC = moving_inverse_transition_function`
5935+ Minvfunc ( ObjectName ) ,
5936+ /// `MSTYPE = moving_state_data_type`
5937+ Mstype ( DataType ) ,
5938+ /// `MSSPACE = moving_state_data_size` (in bytes)
5939+ Msspace ( u64 ) ,
5940+ /// `MFINALFUNC = moving_final_function`
5941+ Mfinalfunc ( ObjectName ) ,
5942+ /// `MFINALFUNC_EXTRA`
5943+ MfinalfuncExtra ,
5944+ /// `MFINALFUNC_MODIFY = { READ_ONLY | SHAREABLE | READ_WRITE }`
5945+ MfinalfuncModify ( AggregateModifyKind ) ,
5946+ /// `MINITCOND = moving_initial_condition` (a string literal)
5947+ Minitcond ( Value ) ,
5948+ /// `SORTOP = sort_operator`
5949+ Sortop ( ObjectName ) ,
5950+ /// `PARALLEL = { SAFE | RESTRICTED | UNSAFE }`
5951+ Parallel ( FunctionParallel ) ,
5952+ /// `HYPOTHETICAL` — marks the aggregate as hypothetical-set.
5953+ Hypothetical ,
5954+ }
5955+
5956+ impl fmt:: Display for CreateAggregateOption {
5957+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5958+ match self {
5959+ Self :: Sfunc ( name) => write ! ( f, "SFUNC = {name}" ) ,
5960+ Self :: Stype ( data_type) => write ! ( f, "STYPE = {data_type}" ) ,
5961+ Self :: Sspace ( size) => write ! ( f, "SSPACE = {size}" ) ,
5962+ Self :: Finalfunc ( name) => write ! ( f, "FINALFUNC = {name}" ) ,
5963+ Self :: FinalfuncExtra => write ! ( f, "FINALFUNC_EXTRA" ) ,
5964+ Self :: FinalfuncModify ( kind) => write ! ( f, "FINALFUNC_MODIFY = {kind}" ) ,
5965+ Self :: Combinefunc ( name) => write ! ( f, "COMBINEFUNC = {name}" ) ,
5966+ Self :: Serialfunc ( name) => write ! ( f, "SERIALFUNC = {name}" ) ,
5967+ Self :: Deserialfunc ( name) => write ! ( f, "DESERIALFUNC = {name}" ) ,
5968+ Self :: Initcond ( cond) => write ! ( f, "INITCOND = {cond}" ) ,
5969+ Self :: Msfunc ( name) => write ! ( f, "MSFUNC = {name}" ) ,
5970+ Self :: Minvfunc ( name) => write ! ( f, "MINVFUNC = {name}" ) ,
5971+ Self :: Mstype ( data_type) => write ! ( f, "MSTYPE = {data_type}" ) ,
5972+ Self :: Msspace ( size) => write ! ( f, "MSSPACE = {size}" ) ,
5973+ Self :: Mfinalfunc ( name) => write ! ( f, "MFINALFUNC = {name}" ) ,
5974+ Self :: MfinalfuncExtra => write ! ( f, "MFINALFUNC_EXTRA" ) ,
5975+ Self :: MfinalfuncModify ( kind) => write ! ( f, "MFINALFUNC_MODIFY = {kind}" ) ,
5976+ Self :: Minitcond ( cond) => write ! ( f, "MINITCOND = {cond}" ) ,
5977+ Self :: Sortop ( name) => write ! ( f, "SORTOP = {name}" ) ,
5978+ Self :: Parallel ( parallel) => {
5979+ let kind = match parallel {
5980+ FunctionParallel :: Safe => "SAFE" ,
5981+ FunctionParallel :: Restricted => "RESTRICTED" ,
5982+ FunctionParallel :: Unsafe => "UNSAFE" ,
5983+ } ;
5984+ write ! ( f, "PARALLEL = {kind}" )
5985+ }
5986+ Self :: Hypothetical => write ! ( f, "HYPOTHETICAL" ) ,
5987+ }
5988+ }
5989+ }
5990+
5991+ /// Modifier kind for `FINALFUNC_MODIFY` / `MFINALFUNC_MODIFY` in `CREATE AGGREGATE`.
5992+ ///
5993+ /// See <https://www.postgresql.org/docs/current/sql-createaggregate.html>
5994+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5995+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5996+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5997+ pub enum AggregateModifyKind {
5998+ /// The final function does not modify the transition state.
5999+ ReadOnly ,
6000+ /// The transition state may be shared between aggregate calls.
6001+ Shareable ,
6002+ /// The final function may modify the transition state.
6003+ ReadWrite ,
6004+ }
6005+
6006+ impl fmt:: Display for AggregateModifyKind {
6007+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6008+ match self {
6009+ Self :: ReadOnly => write ! ( f, "READ_ONLY" ) ,
6010+ Self :: Shareable => write ! ( f, "SHAREABLE" ) ,
6011+ Self :: ReadWrite => write ! ( f, "READ_WRITE" ) ,
6012+ }
6013+ }
6014+ }
6015+
58626016/// `CREATE TEXT SEARCH CONFIGURATION` statement.
58636017///
58646018/// Note: this is a PostgreSQL-specific statement.
0 commit comments