pgrx_macros

Attribute Macro pg_cast

Source
#[pg_cast]
Expand description

Declare a function as #[pg_cast] to indicate that it represents a Postgres cast.

By default if no attribute is specified, the cast function can only be used in an explicit cast.

Functions MUST accept and return exactly one value whose type MUST be a pgrx supported type. pgrx supports many PostgreSQL types by default. New types can be defined via PostgresType or PostgresEnum.

#[pg_cast] also supports all the attributes supported by the [macro@pg_extern] macro, which are passed down to the underlying function.

Example usage:

use pgrx::*;
#[pg_cast(implicit)]
fn cast_json_to_int(input: Json) -> i32 { todo!() }