pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.57k stars 242 forks source link

Support reference type for Aggregate::Args? #1719

Open my-vegetable-has-exploded opened 4 months ago

my-vegetable-has-exploded commented 4 months ago

I want to use impl Aggregate to define aggregate function (to ensure it use aggregate context). But my input args is reference with lifetime, so it is hard to impl Aggregate trait.

Maybe it is another way to add a attr aggcontext for pg_extern? And generate code like pgrx::pg_sys::submodules::panic::pgrx_extern_c_guard(move || { let mut agg_context: *mut ::pgrx::pg_sys::MemoryContextData = std::ptr::null_mut(); if ::pgrx::pg_sys::AggCheckCallContext(_fcinfo, &mut agg_context) == 0 { ::pgrx::error!("aggregate function called in non-aggregate context",); } let old_context = ::pgrx::pg_sys::MemoryContextSwitchTo(agg_context); let result = _vectors_vecf32_aggregate_avg_sum_sfunc_wrapper_inner(_fcinfo); ::pgrx::pg_sys::MemoryContextSwitchTo(old_context); result }) ?

Thanks for your great work.

workingjubilee commented 4 months ago

We are working on the necessary prerequisite code for making that sort of thing possible like right now. We can take a look at revising impl Aggregate for that when it lands.

I would rather not add ad-hoc functionality like that to pg_extern.

workingjubilee commented 4 months ago

The relevant blocking work is most of https://github.com/pgcentralfoundation/pgrx/issues/1661