pgrx
pgrx copied to clipboard
Multiple aggregate on same type
Hello, I'm I would like to define multiple aggregate functions on one of my types: https://github.com/JeanChristopheMorinPerso/data_experiments/blob/c47bca89aab29d96a25a96a475c63a438707a9cd/conda_pgsql_rust_ext/src/lib.rs#L7-L12
I can add at least one aggregate function using the pg_aggregate macro like this:
#[pg_aggregate]
impl Aggregate for CondaVersion {
type State = CondaVersion;
type Args = CondaVersion;
const NAME: &'static str = "min";
const SORT_OPERATOR: Option<&'static str> = Some("condaversion_lt");
fn state(
current: Self::State,
arg: Self::Args,
_fcinfo: pg_sys::FunctionCallInfo
) -> Self::State {
// NOTE THAT I HAVE NOT YET TESTED THIS IMPLEMENTATION
if current <= arg {
return current;
}
return arg;
}
}
This results in
CREATE FUNCTION "conda_version_state"(
"this" CondaVersion, /* conda_pgsql_rust_ext::CondaVersion */
"arg_one" CondaVersion /* conda_pgsql_rust_ext::CondaVersion */
) RETURNS CondaVersion /* conda_pgsql_rust_ext::CondaVersion */
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'conda_version_state_wrapper';
CREATE AGGREGATE min (
CondaVersion /* conda_pgsql_rust_ext::CondaVersion */
)
(
SFUNC = "conda_version_state", /* conda_pgsql_rust_ext::CondaVersion::state */
STYPE = CondaVersion, /* conda_pgsql_rust_ext::CondaVersion */
SORTOP = "condaversion_lt" /* conda_pgsql_rust_ext::CondaVersion::SORT_OPERATOR */
);
But I'm kind of failing to see how I could define a second one... Say, a max aggregate.
Is this possible with pgrx? I'm not very good at rust, so forgive me if this is more a rust question than a pgrx question.
Thanks!