Expand description
pgx
is a framework for creating Postgres extensions in 100% Rust
Example
use pgx::*;
// Convert the input string to lowercase and return
#[pg_extern]
fn my_to_lowercase(input: &'static str) -> String {
input.to_lowercase()
}
Re-exports
pub use pgx_pg_sys as pg_sys;
pub use cstr_core;
pub use pgx_utils as utils;
pub use aggregate::*;
pub use atomics::*;
pub use callbacks::*;
pub use datum::*;
pub use enum_helper::*;
pub use fcinfo::*;
pub use guc::*;
pub use hooks::*;
pub use htup::*;
pub use inoutfuncs::*;
pub use itemptr::*;
pub use list::*;
pub use log::*;
pub use lwlock::*;
pub use memcxt::*;
pub use namespace::*;
pub use nodes::*;
pub use pgbox::*;
pub use rel::*;
pub use shmem::*;
pub use spi::*;
pub use stringinfo::*;
pub use trigger_support::*;
pub use tupdesc::*;
pub use varlena::*;
pub use wrappers::*;
pub use xid::*;
Modules
Safely create Postgres Background Workers, including with full SPI support
Provides safe wrappers around Postgres’ “Transaction” and “Sub Transaction” hook system
Handing for easily converting Postgres Datum types into their corresponding Rust types
and converting Rust types into their corresponding Postgres types
Helper functions for working with Postgres
enum
typesHelper macros and functions for creating Postgres UDFs.
Provides a safe interface into Postgres’ Configuration System (GUC)
Provides a safe interface to Postgres
HeapTuple
objects.A trait and registration system for hooking Postgres internal operations such as its planner and executor
Utility functions for working with
pg_sys::HeapTuple
and pg_sys::HeapTupleHeader
structsHelper trait for the
#[derive(PostgresType)]
proc macro for overriding custom Postgres type
input/output functions.Helper functions for working with Postgres
ItemPointerData
(tid
) typeA safe wrapper around Postgres’ internal
List
structure.Access to Postgres’ logging system
Provides interfacing into Postgres’
MemoryContext
system.A helper struct for creating a Postgres
List
of String
s to qualify an object nameHelper functions and such for Postgres’ various query tree
Node
sThe PGX prelude includes necessary imports to make extensions work.
Provides a safe wrapper around Postgres’
pg_sys::RelationData
structSafe access to Postgres’ Server Programming Interface (SPI).
A safe wrapper around Postgres
StringInfo
structureSupport for writing Rust trigger functions
Provides a safe wrapper around Postgres’
pg_sys::TupleDescData
structHelper functions to work with Postgres
varlena *
structuresProvides safe wrapper functions around some of Postgres’ useful functions.
Macros
Log to Postgres’
fatal
log level. This will abort the current Postgres backend connection processs.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
Composite type support
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 propery translated to SQL in
CREATE FUNCTION
statementsLog 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.
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
std::iter::Iterator<Item=(f1, f2, f3)>
Log to Postgres’
notice
log level.Create the
Pg_magic_func
required by PGX in extensions.A macro for marking a library compatible with
pgx
.In order to store a type in Postgres Shared Memory, it must be passed to
pg_shmem_init!()
during _PG_init()
.Create neccessary extension-local internal marker for use with SQL generation.
Log to Postgres’
warning
log level.Structs
Datum is an abstract value that is effectively a union of all scalar types
and all possible pointers in a Postgres context. That is, it is either
“pass-by-value” (if the value fits into the platform’s
uintptr_t
) or
“pass-by-reference” (if it does not).This struct consists of a Datum and a bool, matching Postgres’s definition
as of Postgres 12. This isn’t efficient in terms of storage size, due to padding,
but sometimes it’s more cache-friendly, so sometimes it is the preferred type.
A
std::result::Result
-type value returned from pg_try()
that allows for performing cleanup
work after a closure raised an error and before it is possibly rethrownEnums
Statics
Functions
Guard a closure such that Rust Panics are properly converted into Postgres ERRORs
Initialize the extension with Postgres
Converts a
pg_sys::NameData
struct into a &str
.Similar to
guard
, but allows the caller to unwrap the result in various ways, possibly
performing cleanup work before the caught error is rethrownAttribute Macros
Used with
#[pg_operator]
. 1 value which is the function nameUsed with
#[pg_operator]
. no valuesAssociated macro for
#[pg_test]
to provide context back to your test framework to indicate
that the test system is being initializedUsed with
#[pg_operator]
. 1 value which is the function nameUsed with
#[pg_operator]
. no valuesUsed with
#[pg_operator]
. 1 value which is the function nameUsed with
#[pg_operator]
. 1 value which is the operator name itselfDeclare a
pgx::Aggregate
implentation 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 Postgres extern "C"
function so that Rust panic!()
s (and Postgres elog(ERROR)
s) will be properly handled by pgx
Declare a function as
#[pg_operator]
to indicate that it represents a Postgres operator
cargo pgx schema
will automatically generate the underlying SQLDeclare 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 during cargo pgx test
.A helper attribute for various contexts.
Used with
#[pg_operator]
. 1 value which is the function nameAssociated macro for
#[pg_extern]
or #[macro@pg_operator]
. Used to set the SEARCH_PATH
option
on the CREATE FUNCTION
statement.Derive Macros
Generate necessary bindings for using the enum with PostgreSQL.
Generate necessary code using the type in operators like
==
and !=
.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.