[−][src]Function pgx::fcinfo::direct_function_call
pub unsafe fn direct_function_call<R: FromDatum>(
func: unsafe fn(_: FunctionCallInfo) -> Datum,
args: Vec<Option<Datum>>
) -> Option<R>
As #[pg_extern]
functions are wrapped with a different signature, this
allows you to directly call them.
This mimics the functionality of Postgres' DirectFunctionCall
macros, allowing you to call
Rust-defined functions. Unlike Postgres' macros, the directly called function is allowed to
return a NULL datum.
You'll just need to account for that when using .try_into()
to convert the datum into a rust
type.
Note
You must suffix the function name with _wrapper
, as shown in the example below.
Safety
This function is unsafe as the underlying function being called is likely unsafe
Examples
use pgx::*; #[pg_extern] fn add_two_numbers(a: i32, b: i32) -> i32 { a + b } fn some_func() { let result = unsafe { direct_function_call::<i32>(add_two_numbers_wrapper, vec!(2.into_datum(), 3.into_datum())) }; let sum = result.expect("function returned null"); assert_eq!(sum, 5); }