Trait pgx::aggregate::Aggregate

source ·
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§

source

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.

source

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.

source

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.

source

type Finalize

Optional: This function can be skipped, #[pg_aggregate] will create a stub.

source

type MovingState

Optional: This function can be skipped, #[pg_aggregate] will create a stub.

Required Associated Constants§

source

const NAME: &'static str

The name of the aggregate. (eg. What you’d pass to SELECT agg(col) FROM tab.)

Provided Associated Constants§

source

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.

source

const PARALLEL: Option<ParallelOption> = None

Optional: This const can be skipped, #[pg_aggregate] will create a stub.

source

const FINALIZE_MODIFY: Option<FinalizeModify> = None

Optional: This const can be skipped, #[pg_aggregate] will create a stub.

source

const MOVING_FINALIZE_MODIFY: Option<FinalizeModify> = None

Optional: This const can be skipped, #[pg_aggregate] will create a stub.

source

const INITIAL_CONDITION: Option<&'static str> = None

Optional: This const can be skipped, #[pg_aggregate] will create a stub.

source

const SORT_OPERATOR: Option<&'static str> = None

Optional: This const can be skipped, #[pg_aggregate] will create a stub.

source

const MOVING_INITIAL_CONDITION: Option<&'static str> = None

Optional: This const can be skipped, #[pg_aggregate] will create a stub.

source

const HYPOTHETICAL: bool = false

Optional: This const can be skipped, #[pg_aggregate] will create a stub.

Required Methods§

source

fn state( current: Self::State, v: Self::Args, fcinfo: FunctionCallInfo ) -> Self::State

source

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.

source

fn combine( current: Self::State, _other: Self::State, fcinfo: FunctionCallInfo ) -> Self::State

Optional: This function can be skipped, #[pg_aggregate] will create a stub.

source

fn serial(current: Self::State, fcinfo: FunctionCallInfo) -> Vec<u8>

Optional: This function can be skipped, #[pg_aggregate] will create a stub.

source

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.

source

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.

source

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.

source

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.

Provided Methods§

Implementors§