This is pgx v0.7.0-beta.0. Other than pgx' initial release, this is our biggest release yet! It contains a number of safety improvements, segfault fixes, API changes, minor performance improvements, and an overhauled Spi interface now with prepared statements and cursors!
Quite a number of people have contributed to this release, so a big thank you is necessary right here at the top. Some notable names are @yrashk and @EdMcBane for their work on Spi. And a shout-out to the new contributors: @jaskij, @kianmeng, and @ChuckHend.
To use this beta release, install cargo-pgx
by version: $ cargo install cargo-pgx --version 0.7.0-beta.0 --locked
and make sure to update your extension crate dependencies to use 0.7.0-beta.0
too.
API Changes
v0.7.0 contains some backwards incompatible API changes and your extension code may need to be updated as a result. Leaning on the compiler should help you through the changes.
pgbox::WhoAllocated<T>
doesn't need to be generic over anyT
by @eeeebbbbrrrr in #901- Lift
UnwindSafe + RefUnwindSafe
bounds in PgMemoryContexts by @eeeebbbbrrrr in #986 impl Clone for PgTupleDesc
by @mhov in #962AnyElement::into()
needs to be unsafe by @eeeebbbbrrrr in #928- Lets make
pg_guard_ffi_boundary
public for everyone to enjoy! by @eeeebbbbrrrr in #942 - Mark many functions
unsafe
that should be by @eeeebbbbrrrr in #995 - allow
#![forbid(unsafe_op_in_unsafe_fn)]
to work with pgx-generated… by @eeeebbbbrrrr in #996 pg_sys::Oid
is now a newtype wrapper around au32
by @workingjubilee in #1000 & #1004
Spi
Spi has received a major overhaul in v0.7.0. It now supports cursors, prepared statements, and runtime datum conversion error detection.
Much of the Spi API has been overhauled in a backwards-incompatible way, and is too much to document in release notes. However, the biggest change is that the various getter functions on Spi
and SpiTupleTable
and SpiHeapTupleData
now return pgx::spi::Result<Option<T>>
. The error type is pgx::spi::Error
and can not only report Postgres-specific SPI_ERROR_XXX
errors from Postgres but also represent runtime situations where the requested Rust type T
isn't compatible with the backing Datum type.
Cursor Support Changes
- Add support for Spi cursors by @EdMcBane in #579
- ensure multiple open SpiTupTables can coexist by @EdMcBane in #938
- Cursor API should not require
&self mut
by @yrashk in #934 - Minor code improvement for open_cursor by @yrashk in #935
Prepared Statement Support
Spi Statement "readonly" Management
- Make non-updating queries use
readonly
until transaction end unless there was a prior mutation by @yrashk/@eeeebbbbrrrr in #963 & #992 fix issue #983 by @eeeebbbbrrrr in #984(was replaced by #992)
Spi Error Handling
Because most Spi-related functions now return spi::Result<T>
, pgx now knows how to convert a Result<T: IntoDatum, E: Any + Display>
into a Datum
. This means #[pg_extern]
-style functions (including #[pg_test]
functions) can now return a Result. This makes working with Spi much more "rust-like" and fluent.
If result is Ok
then its payload is converted into a Datum. If the result is Err
, then pgx will automatically raise a Postgres ERROR
. Furthermore, if the Err
variant's payload is a pgx ErrorReport
, then that'll be raised, which can include a specific SQL error code, detail, hint, and context message.
The general work on Spi error handling happened in these PRs, with much help from @yrashk and @EdMcBane:
- Build upon #902 by @yrashk: Spi Error Handling by @eeeebbbbrrrr in #969
- Proper error handling for SPI by @eeeebbbbrrrr in #977
- Add type/oid details to Datum conversion errors by @EdMcBane in #985
And the generalized support for handling Results-as-Datums came in through:
impl IntoDatum for Result<T: IntoDatum, E: Display>
by @eeeebbbbrrrr in #972- Change bounds on
IntoDatum for Result<T, E>
such thatE: Any + Display
by @eeeebbbbrrrr in #973 - Support returning
Result<TableIterator/SetOfIterator, E>
by @eeeebbbbrrrr in #975 - Fix a bug trying to return
Result<pg_sys::Oid>
by @eeeebbbbrrrr in #976
General Cleanups
- Improve the safety documentation for
pg_guard_ffi_boundary
by @thomcc in #957 - Fix typos by @kianmeng in #959
- cargo-pgx: deny clippy::perf by @workingjubilee in #933
- Silence clippy in
pgx-version-updater
by @workingjubilee in #930 - sql-entity-graph: fix clippy::if_same_then_else by @workingjubilee in #931
- Fix pgx-sql-entity-graph impls of derivable traits. by @thomcc in #929
pgx-utils
crate renamed topgx-sql-entity-graph
by @eeeebbbbrrrr in #911- pgx-pg-sys: cshim: Makefile: user AR variable by @jaskij in #937
- Fully qualify all pgx symbol references during code generation by @eeeebbbbrrrr in #925
- fully qualify the path to #[pg_guard] during code generation by @eeeebbbbrrrr in #943
- Document and simplify
cargo-pgx
version matching requirement by @yrashk in #964 - Remove specific versions from getting started section by @rustprooflabs in #991
- Revert "Revert "Replace rayon"" by @workingjubilee in #945
- localize some use statements by @eeeebbbbrrrr in #944
- add doc to pg_test module in template by @ChuckHend in #970
- fix compilation on arm by @eeeebbbbrrrr in #993
- Preliminary support for cross-compilation on Linux<-->Linux for x86_64 to aarch64 by @thomcc in #1003
This one is particularly interesting as it now allows cargo test --all --features "pgXX ... ..."
to work from a top-level workspace crate:
- Teach
pgx-tests/src/framework.rs
to detectcargo test
feature arguments by @eeeebbbbrrrr in #967
Stability, Correctness, and Performance
- Problem: can't use
pg_guard
on parameterized functions by @yrashk in #918 - Handle panics in PgMemoryContexts::switch_to by @yrashk in #920
- Ensure setting owned memory context as current twice won't lead to problems (bugfix) by @yrashk in #956
- Improve error handling during code generation by converting some panics into
syn::Error
s by @thomcc in #919 - Set returning
#[pg_extern]
functions can cause segfault by @eeeebbbbrrrr in #982- Move generated SRF code into managed code by @eeeebbbbrrrr in #987
- PgLwLock: skip releasing the lock when unwinding from an
elog
call in postgres code by @EdMcBane in #989 - :enh: bail out early in do_ereport if errstart returns false by @EdMcBane in #980
- Rewrite
StringInfo
by @eeeebbbbrrrr in #903 - Optimize our String/&str/Vec/&[u8] IntoDatum conversions by @eeeebbbbrrrr in #952
Feature Flags
- A
pgx/no-schema-generation
feature flag by @eeeebbbbrrrr in #915
When enabled, pgx will not generate any code related to the "sql entity graph", thereby causing cargo-pgx
to generate an empty schema.
- Add a default
pgx/cshim
feature flag by @eeeebbbbrrrr in #958 - The
cshim
feature should not be a default inpgx-pg-sys
. by @eeeebbbbrrrr in #990
When enabled (which is the default), pgx
(specifically, pgx-pg-sys
) will compile its "cshim" code and have it statically linked into the extension. Disabling this feature flag might make pgx compilation easier for platforms where the necessary Postgres C extension build requirements aren't available, however you'll lose access to a few pgx modules: hooks
, list
, namespace
and spinlock
.
Our ultimate goal is to not have a "cshim" at all, and to that end much of the old "cshim" has been ported to Rust:
- Port c-shim.c
heap_getattr
,HeapTupleHeaderGetXmin
, andHeapTupleHeaderGetRawCommandId
to Rust by @eeeebbbbrrrr in #953 - Port c-shim.c
pgx_GETSTRUCT
andpgx_HeapTupleHeaderGetOid
to Rust by @eeeebbbbrrrr in #950 - Port various c-shim.c
SET_VARSIZE*
functions to Rust by @eeeebbbbrrrr in #949 PgMemoryContexts::get_context_for_pointer()
is wildly unsafe. by @eeeebbbbrrrr in #947- Port
c-shim.c
'spgx_ereport()
function to rust by @eeeebbbbrrrr in #946 - Port various c-shim.c
ARR_*
functions to Rust by @eeeebbbbrrrr in #948
More Postgres Headers
CI Updates
- Fixes will-it-blend nightly by @BradyBonnette in #916
- Adds unlocked cargo runs to Will It Blend CI by @BradyBonnette in #966
New Contributors
- @jaskij made their first contribution in #937
- @kianmeng made their first contribution in #959
- @ChuckHend made their first contribution in #970
A Note From @eeeebbbbrrrr
To all the pgx users and most especially the contributors that had PRs open for awhile, and then has those PRs merged to just sit there even longer, thank you for being patient. I, and the core pgx team, recognize that was a thing.
I personally wanted v0.7.0 to collect as many breaking changes as we could, especially around Spi, in the hopes that future releases will have far fewer breaking changes. I also wanted the Spi overhaul to be worth the wait, and I really believe it is!
I can't promise that future releases will have less breaking changes, but that is a goal.
Full Changelog: v0.6.1...v0.7.0-beta.0