pub trait Aggregatewhere
Self: Sized,{
type State;
type Args;
type OrderedSetArgs;
type Finalize;
type MovingState;
Show 9 associated constants and 10 methods
const NAME: &'static str;
const ORDERED_SET: bool = false;
const PARALLEL: Option<ParallelOption> = None;
const FINALIZE_MODIFY: Option<FinalizeModify> = None;
const MOVING_FINALIZE_MODIFY: Option<FinalizeModify> = None;
const INITIAL_CONDITION: Option<&'static str> = None;
const SORT_OPERATOR: Option<&'static str> = None;
const MOVING_INITIAL_CONDITION: Option<&'static str> = None;
const HYPOTHETICAL: bool = false;
// Required methods
fn state(
current: Self::State,
v: Self::Args,
fcinfo: FunctionCallInfo
) -> Self::State;
fn finalize(
current: Self::State,
direct_args: Self::OrderedSetArgs,
fcinfo: FunctionCallInfo
) -> Self::Finalize;
fn combine(
current: Self::State,
_other: Self::State,
fcinfo: FunctionCallInfo
) -> Self::State;
fn serial(current: Self::State, fcinfo: FunctionCallInfo) -> Vec<u8>;
fn deserial(
current: Self::State,
_buf: Vec<u8>,
_internal: PgBox<Self::State>,
fcinfo: FunctionCallInfo
) -> PgBox<Self::State>;
fn moving_state(
_mstate: Self::MovingState,
_v: Self::Args,
fcinfo: FunctionCallInfo
) -> Self::MovingState;
fn moving_state_inverse(
_mstate: Self::MovingState,
_v: Self::Args,
fcinfo: FunctionCallInfo
) -> Self::MovingState;
fn moving_finalize(
_mstate: Self::MovingState,
direct_args: Self::OrderedSetArgs,
fcinfo: FunctionCallInfo
) -> Self::Finalize;
// Provided methods
unsafe fn memory_context(fcinfo: FunctionCallInfo) -> Option<MemoryContext> { ... }
fn in_memory_context<R, F: FnOnce(&mut PgMemoryContexts) -> R + UnwindSafe + RefUnwindSafe>(
fcinfo: FunctionCallInfo,
f: F
) -> R { ... }
}
Expand description
Aggregate implementation trait.
When decorated with #[pgx_macros::pg_aggregate]
, enables the
generation of CREATE AGGREGATE
SQL.
The #[pgx_macros::pg_aggregate]
will automatically fill fields
marked optional with stubs.
Required Associated Types§
sourcetype State
type State
The type of the return value on state
and combine
functions.
For an aggregate type which does not have a PgVarlenaInOutFuncs
implementation,
this can be left out, or set to it’s default, Self
.
For an aggregate type which does have a PgVarlenaInOutFuncs
implementation,
this should be set to PgVarlena<Self>
.
Other types are supported as well, this can be useful if multiple aggregates share a state.
sourcetype Args
type Args
The type of the argument(s).
For a single argument, provide the type directly.
For multiple arguments, provide a tuple.
Use pgx::name!()
to set the SQL name of the argument.
If the final argument is to be variadic, use pgx::variadic
. When used
with pgx::name!()
, it must be used inside the pgx::name!()
macro.
sourcetype OrderedSetArgs
type OrderedSetArgs
The types of the direct argument(s) to an ordered-set aggregate’s finalize
.
Only effective if ORDERED_SET
is true
.
For a single argument, provide the type directly.
For multiple arguments, provide a tuple.
For no arguments, don’t set this, or set it to ()
(the default).
pgx
does not support argname
as it is only used for documentation purposes.
If the final argument is to be variadic, use pgx::Variadic
.
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
sourcetype MovingState
type MovingState
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
Required Associated Constants§
Provided Associated Constants§
sourceconst ORDERED_SET: bool = false
const ORDERED_SET: bool = false
Set to true if this is an ordered set aggregate.
If set, the OrderedSetArgs
associated type becomes effective, this allows for
direct arguments to the finalize
function.
See https://www.postgresql.org/docs/current/xaggr.html#XAGGR-ORDERED-SET-AGGREGATES for more information.
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
sourceconst PARALLEL: Option<ParallelOption> = None
const PARALLEL: Option<ParallelOption> = None
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
sourceconst FINALIZE_MODIFY: Option<FinalizeModify> = None
const FINALIZE_MODIFY: Option<FinalizeModify> = None
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
sourceconst MOVING_FINALIZE_MODIFY: Option<FinalizeModify> = None
const MOVING_FINALIZE_MODIFY: Option<FinalizeModify> = None
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
sourceconst INITIAL_CONDITION: Option<&'static str> = None
const INITIAL_CONDITION: Option<&'static str> = None
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
sourceconst SORT_OPERATOR: Option<&'static str> = None
const SORT_OPERATOR: Option<&'static str> = None
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
sourceconst MOVING_INITIAL_CONDITION: Option<&'static str> = None
const MOVING_INITIAL_CONDITION: Option<&'static str> = None
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
sourceconst HYPOTHETICAL: bool = false
const HYPOTHETICAL: bool = false
Optional: This const can be skipped, #[pg_aggregate]
will create a stub.
Required Methods§
fn state( current: Self::State, v: Self::Args, fcinfo: FunctionCallInfo ) -> Self::State
sourcefn finalize(
current: Self::State,
direct_args: Self::OrderedSetArgs,
fcinfo: FunctionCallInfo
) -> Self::Finalize
fn finalize( current: Self::State, direct_args: Self::OrderedSetArgs, fcinfo: FunctionCallInfo ) -> Self::Finalize
The OrderedSetArgs
is ()
unless ORDERED_SET
is true
and OrderedSetArgs
is configured.
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
sourcefn combine(
current: Self::State,
_other: Self::State,
fcinfo: FunctionCallInfo
) -> Self::State
fn combine( current: Self::State, _other: Self::State, fcinfo: FunctionCallInfo ) -> Self::State
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
sourcefn serial(current: Self::State, fcinfo: FunctionCallInfo) -> Vec<u8>
fn serial(current: Self::State, fcinfo: FunctionCallInfo) -> Vec<u8>
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
sourcefn deserial(
current: Self::State,
_buf: Vec<u8>,
_internal: PgBox<Self::State>,
fcinfo: FunctionCallInfo
) -> PgBox<Self::State>
fn deserial( current: Self::State, _buf: Vec<u8>, _internal: PgBox<Self::State>, fcinfo: FunctionCallInfo ) -> PgBox<Self::State>
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
sourcefn moving_state(
_mstate: Self::MovingState,
_v: Self::Args,
fcinfo: FunctionCallInfo
) -> Self::MovingState
fn moving_state( _mstate: Self::MovingState, _v: Self::Args, fcinfo: FunctionCallInfo ) -> Self::MovingState
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
sourcefn moving_state_inverse(
_mstate: Self::MovingState,
_v: Self::Args,
fcinfo: FunctionCallInfo
) -> Self::MovingState
fn moving_state_inverse( _mstate: Self::MovingState, _v: Self::Args, fcinfo: FunctionCallInfo ) -> Self::MovingState
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.
sourcefn moving_finalize(
_mstate: Self::MovingState,
direct_args: Self::OrderedSetArgs,
fcinfo: FunctionCallInfo
) -> Self::Finalize
fn moving_finalize( _mstate: Self::MovingState, direct_args: Self::OrderedSetArgs, fcinfo: FunctionCallInfo ) -> Self::Finalize
The OrderedSetArgs
is ()
unless ORDERED_SET
is true
and OrderedSetArgs
is configured.
Optional: This function can be skipped, #[pg_aggregate]
will create a stub.