Derive Macro pgrx::PostgresType

source ·
#[derive(PostgresType)]
{
    // Attributes available to this derive:
    #[inoutfuncs]
    #[pgvarlena_inoutfuncs]
    #[requires]
    #[pgrx]
}
Expand description

Generate necessary bindings for using the type with PostgreSQL.

use pgrx::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PostgresType)]
struct Dog {
    treats_received: i64,
    pets_gotten: i64,
}

#[derive(Debug, Serialize, Deserialize, PostgresType)]
enum Animal {
    Dog(Dog),
}

Optionally accepts the following attributes:

  • inoutfuncs(some_in_fn, some_out_fn): Define custom in/out functions for the type.
  • pgvarlena_inoutfuncs(some_in_fn, some_out_fn): Define custom in/out functions for the PgVarlena of this type.
  • sql: Same arguments as #[pgrx(sql = ..)].