Expand description
The PGX prelude includes necessary imports to make extensions work.
Re-exports
pub use ::pgx_pg_sys as pg_sys;
pub use crate::iter::SetOfIterator;
pub use crate::iter::TableIterator;
pub use crate::heap_tuple::PgHeapTuple;
pub use crate::heap_tuple::PgHeapTupleError;
pub use crate::pgbox::AllocatedByPostgres;
pub use crate::pgbox::AllocatedByRust;
pub use crate::pgbox::PgBox;
pub use crate::pgbox::WhoAllocated;
pub use crate::datum::AnyNumeric;
pub use crate::datum::Numeric;
pub use crate::datum::PostgresType;
pub use crate::inoutfuncs::InOutFuncs;
pub use crate::inoutfuncs::JsonInOutFuncs;
pub use crate::inoutfuncs::PgVarlenaInOutFuncs;
pub use crate::trigger_support::PgTrigger;
pub use crate::trigger_support::PgTriggerError;
pub use crate::trigger_support::PgTriggerLevel;
pub use crate::trigger_support::PgTriggerOperation;
pub use crate::trigger_support::PgTriggerWhen;
pub use crate::aggregate::Aggregate;
pub use crate::spi;
pub use crate::spi::Spi;
Macros
- Log to Postgres’
fatal
log level. This will abort the current Postgres backend connection process. - Log to Postgres’
panic
log level. This will cause the entire Postgres cluster to crash. - If an interrupt is pending (perhaps a user-initiated “cancel query” message to this backend), this will safely abort the current transaction
- Log to Postgres’
debug1
log level. - Log to Postgres’
debug2
log level. - Log to Postgres’
debug3
log level. - Log to Postgres’
debug4
log level. - Log to Postgres’
debug5
log level. - A macro for specifying default argument values so they get properly translated to SQL in
CREATE FUNCTION
statements - Sends some kind of message to Postgres, and if it’s a PgLogLevel::ERROR or greater, Postgres’ error handling takes over and, in the case of PgLogLevel::ERROR, aborts the current transaction.
- Log to Postgres’
error
log level. This will abort the current Postgres transaction. - Declare SQL to be included in generated extension script.
- Declare SQL (from a file) to be included in generated extension script.
- This macro returns the name of the enclosing function. As the internal implementation is based on the
std::any::type_name
, this macro derives all the limitations of this function. - Log to Postgres’
info
log level. - Log to Postgres’
log
log level. - A macro for providing SQL names for the returned fields for functions that return a Rust tuple, especially those that return a
TableIterator
. - Log to Postgres’
notice
log level. - A macro for marking a library compatible with
pgx
. - Log to Postgres’
warning
log level.
Structs
- An array of some type (eg.
TEXT[]
,int[]
) - From the PG docs https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT Internally interval values are stored as months, days, and microseconds. This is done because the number of days in a month varies, and a day can have 23 or 25hours if a daylight savings time adjustment is involved. The months and days fields are integers while the microseconds field can store fractional seconds. Because intervals are usually created from constant strings or timestamp subtraction, this storage method works well in most cases…
- Wraps a Postgres
varlena *
, presenting it as if it’s a Rust type of a fixed size. - A safe deconstruction of a Postgres
pg_sys::RangeType
struct.
Enums
- Postgres’ various logging levels
- This list of SQL Error Codes is taken directly from Postgres 12’s generated “utils/errcodes.h”
- A Postgres Range’s “lower” or “upper” value
Constants
Traits
- Convert a
(pg_sys::Datum, is_null:bool
pair into a Rust type - Convert a Rust type into a
pg_sys::Datum
. - This trait allows a struct to be a valid subtype for a RangeType
Functions
- Converts a
pg_sys::NameData
struct into a&str
.
Type Definitions
Attribute Macros
- Used with
#[pg_operator]
. 1 value which is the function name - Used with
#[pg_operator]
. no values - Associated macro for
#[pg_test]
to provide context back to your test framework to indicate that the test system is being initialized - Used with
#[pg_operator]
. 1 value which is the function name - Used with
#[pg_operator]
. no values - Used with
#[pg_operator]
. 1 value which is the function name - Used with
#[pg_operator]
. 1 value which is the operator name itself - Declare a
pgx::Aggregate
implementation on a type as able to used by Postgres as an aggregate. - Declare a function as
#[pg_extern]
to indicate that it can be used by Postgres as a UDF. - Declare a function as
#[pg_guard]
to indicate that it is called from a Postgresextern "C"
function so that Rustpanic!()
s (and Postgreselog(ERROR)
s) will be properly handled bypgx
- Declare a function as
#[pg_operator]
to indicate that it represents a Postgres operatorcargo pgx schema
will automatically generate the underlying SQL - Declare a Rust module and its contents to be in a schema.
#[pg_test]
functions are test functions (akin to#[test]
), but they run in-process inside Postgres duringcargo pgx test
.- Create a PostgreSQL trigger function
- A helper attribute for various contexts.
- Used with
#[pg_operator]
. 1 value which is the function name - Associated macro for
#[pg_extern]
or#[macro@pg_operator]
. Used to set theSEARCH_PATH
option on theCREATE FUNCTION
statement.
Derive Macros
- Generate necessary bindings for using the enum with PostgreSQL.
- Generate necessary code using the type in operators like
==
and!=
. - Derives the
GucEnum
trait, so that normal Rust enums can be used as a GUC. - Generate necessary code for stable hashing the type so it can be used with
USING hash
indexes. - Generate necessary code using the type in operators like
>
,<
,<=
, and>=
. - Generate necessary bindings for using the type with PostgreSQL.