Skip to main content

impl_sql_translatable

Macro impl_sql_translatable 

Source
macro_rules! impl_sql_translatable {
    ($ty:ty, $sql:literal) => { ... };
    ($ty:ty, arg_only = $sql:literal) => { ... };
}
Expand description

Implements SqlTranslatable for a type with a fixed external SQL mapping.

This macro uses pgrx_resolved_type!(T) for TYPE_IDENT, sets TYPE_ORIGIN to TypeOrigin::External, and fills in the const SQL metadata for the common “map this Rust wrapper to an existing SQL type” case.

Spell out the unsafe impl SqlTranslatable instead when (1) the type is owned by this extension or (2) when its argument and return SQL need different mappings.

This macro is re-exported by pgrx and is also available through pgrx::prelude::*.

§Examples

A wrapper that maps to the existing uuid type:

use pgrx::prelude::*;

pub struct UuidWrapper(uuid::Uuid);

impl_sql_translatable!(UuidWrapper, "uuid");

An argument-only wrapper for a pseudo-type:

use pgrx::prelude::*;

pub struct InternalArg(*mut core::ffi::c_void);

impl_sql_translatable!(InternalArg, arg_only = "internal");