Expand description
pgrx is a framework for creating Postgres extensions in 100% Rust
§Example
use pgrx::prelude::*;
// Convert the input string to lowercase and return
#[pg_extern]
fn my_to_lowercase(input: &str) -> String {
input.to_lowercase()
}
Re-exports§
pub use datum::numeric;pub use datum::AnyArray;pub use datum::AnyElement;pub use datum::AnyNumeric;pub use datum::Array;pub use datum::FromDatum;pub use datum::Inet;pub use datum::Internal;pub use datum::IntoDatum;pub use datum::Json;pub use datum::JsonB;pub use datum::Numeric;pub use datum::Range;pub use datum::Uuid;pub use datum::VariadicArray;pub use spi::Spi;pub use pgrx_macros;pub use aggregate::*;pub use atomics::*;pub use callbacks::*;pub use enum_helper::*;pub use fcinfo::*;pub use guc::*;pub use hooks::*;Deprecated pub use htup::*;pub use inoutfuncs::*;pub use list::old_list::*;pub use lwlock::*;pub use memcxt::*;pub use namespace::*;pub use nodes::*;pub use pgbox::*;pub use rel::*;pub use shmem::*;pub use stringinfo::*;pub use trigger_support::*;pub use tupdesc::*;pub use varlena::*;pub use wrappers::*;pub use xid::*;
Modules§
- Aggregate support.
- Safely create Postgres Background Workers, including with full SPI support
- Provides safe wrappers around Postgres’ “Transaction” and “Sub Transaction” hook system
- Helper implementations for returning sets and tables from
#[pg_extern]-style functions - 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
enumtypes - Helper functions for creating Postgres UDFs
- Reexport FFI definitions here.
- Provides a safe interface into Postgres’ Configuration System (GUC)
- Provides a safe interface to Postgres
HeapTupleobjects. - hooks
Deprecated A trait and registration system for hooking Postgres internal operations such as its planner and executor - Utility functions for working with
pg_sys::HeapTupleandpg_sys::HeapTupleHeaderstructs - Helper trait for the
#[derive(PostgresType)]proc macro for overriding custom Postgres type input/output functions. - Helper functions for working with Postgres
ItemPointerData(tid) type - Code for interfacing with the layout in memory (and on disk?) of various data types within Postgres. This is not a mature module yet so prefer to avoid exposing the contents to public callers of pgrx, as this is error-prone stuff to tamper with. It is easy to corrupt the database if an error is made. Yes, even though its main block of code duplicates htup::DatumWithTypeInfo.
- A safe wrapper around Postgres’ internal
Liststructure. - Memory Contexts in PostgreSQL, now with lifetimes.
- Provides interfacing into Postgres’
MemoryContextsystem. - A helper struct for creating a Postgres
ListofStrings to qualify an object name - Helper functions and such for Postgres’ various query tree
Nodes - Traits and implementations of functionality relating to Postgres null and nullable types, particularly in relation to arrays and other container types which implement nullable (empty slot) behavior in a “structure-of-arrays” manner
- dirty hacks
- The PGRX prelude includes necessary imports to make extensions work.
- Provides a safe wrapper around Postgres’
pg_sys::RelationDatastruct - Safe access to Postgres’ Server Programming Interface (SPI).
- A safe wrapper around Postgres
StringInfostructure - Support for writing Rust trigger functions
- Provides a safe wrapper around Postgres’
pg_sys::TupleDescDatastruct - Helper functions to work with Postgres
varlena *structures - Provides safe wrapper functions around some of Postgres’ useful functions.
Macros§
- Log to Postgres’
fatallog level. This will abort the current Postgres backend connection process. - Log to Postgres’
paniclog 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’
debug1log level. - Log to Postgres’
debug2log level. - Log to Postgres’
debug3log level. - Log to Postgres’
debug4log level. - Log to Postgres’
debug5log level. - A macro for specifying default argument values so they get properly translated to SQL in
CREATE FUNCTIONstatements - 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’
errorlog 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’
infolog level. - Log to Postgres’
loglog 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’
noticelog level. - Create the
Pg_magic_funcrequired by PGRX in extensions. - A macro for marking a library compatible with
pgrx. - In order to store a type in Postgres Shared Memory, it must be passed to
pg_shmem_init!()during_PG_init(). - Entry point for cargo-pgrx’s schema generation so that PGRX’s framework can generate SQL for its types and functions and topographically sort them into an order Postgres will accept. Typically written by the
cargo pgrx newtemplate, so you probably don’t need to worry about this. - variadic
Deprecated - Log to Postgres’
warninglog level.
Structs§
Enums§
- Postgres’ various logging levels
- This list of SQL Error Codes is taken directly from Postgres 12’s generated “utils/errcodes.h”
Constants§
Functions§
- Converts a
pg_sys::NameDatastruct into a&str.
Type Aliases§
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
pgrx::Aggregateimplementation on a type as able to used by Postgres as an aggregate. - Declare a function as
#[pg_cast]to indicate that it represents a Postgres cast. - 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 bypgrx - Declare a function as
#[pg_operator]to indicate that it represents a Postgres operatorcargo pgrx schemawill 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 pgrx 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_PATHoption on theCREATE FUNCTIONstatement.
Derive Macros§
- Generate necessary bindings for using the enum with PostgreSQL.
- Generate necessary code using the type in operators like
==and!=. - Derives the
GucEnumtrait, 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 hashindexes. - Generate necessary code using the type in operators like
>,<,<=, and>=. - Generate necessary bindings for using the type with PostgreSQL.