v0.5.0-beta.0
Pre-releaseThis is an experimental version for the upcoming 0.5.0 release.
Make sure to run cargo install --locked cargo-pgx --version 0.5.0-beta.0
.
Handling Datums
pg_sys::Datum
is no longer type Datum = usize;
, but a "newtype": a struct wrapping a pointer that indicates it is an opaque type. This is for correctness and to better represent the unique nature of the type with respect to Postgres. A fair amount of your code may have relied on T as pg_sys::Datum
or datum as T
working. Certainly some in pgx
did, resulting in patterns like:
// generating fresh arrays for data
let mut datums: Vec<pg_sys::Datum> = vec![0; N];
let mut nulls = vec![false; N];
// treating a datum as a pass-by-value type
let index = datum as i32;
// treating a datum as a pointer type
let varlena = datum as *mut pg_sys::varlena;
Now it doesn't! To make the transition easy, From<T> for pg_sys::Datum
is implemented for everything it is reasonable to convert directly into it in a "by-value" fashion. Use IntoDatum
for anything more complex. To get the usize
hiding inside Datum
out, use Datum::value(self) -> usize
, to cast it as a pointer, Datum::ptr_cast::<T>(self) -> *mut T
is available.
// (getting|putting) data (from|into) Postgres as a datum array
let mut datums = vec![pg_sys::Datum::from(0); N];
let mut nulls = vec![false; N];
// treating a datum as a pass-by-value type
let index = datum.value() as i32;
// treating a datum as a pointer type
let varlena = datum.ptr_cast::<pg_sys::varlena>();
Because a pg_sys::Datum
is a union of types, only certain traits that are implemented on usize
are also implemented on Datum
, as it was deemed safest to limit implementations to those that are also valid if Datum
is a pointer or float. This can induce code to reveal any assumptions it was making.
Enhancements
Considerable enhancements have been made to heap tuple and trigger support, introducing pg_trigger
and a new PgHeapTuple
type! Try them out!
- Improved "HeapTuple" support by @eeeebbbbrrrr in #532
- Trigger support improvements by @Hoverbear in #558
Fixes
- Hang onto libraries by @Hoverbear in #573
Acargo pgx
bug that could cause segfaults on old versions of glibc was fixed by no longer usingdlclose
on the libraries we dynamically load until the process ends.
Experimental features
You may have noticed the "postgrestd"
feature. This is a highly experimental feature for using PGX to back a very special configuration of Rust as a trusted procedural language: PL/Rust. It's best to assume this feature can induce unsound changes if they aren't combined with the rest of the configuration for the trusted language handler's building and running of functions.
Full Changelog: v0.4.5...v0.5.0-beta.0