Macro pgrx::default

source ·
macro_rules! default {
    ($ty:ty, $val:tt) => { ... };
    ($ty:ty, $val:path) => { ... };
    ($ty:ty, $val:expr) => { ... };
}
Expand description

A macro for specifying default argument values so they get properly translated to SQL in CREATE FUNCTION statements

§Examples

This example will create a SQL function like so:

CREATE FUNCTION fun_with_default_arg_value(a integer, b integer DEFAULT 99) RETURNS integer ...;
use pgrx::prelude::*;

#[pg_extern]
fn fun_with_default_arg_value(a: i32, b: default!(i32, 99)) -> i32 {
   a + b
}

This allows users of this function, from within Postgres, to elide the b argument, and Postgres will automatically use 99.