github pgcentralfoundation/pgrx v0.6.0

latest releases: v0.12.4, v0.12.3, v0.12.2...
21 months ago

This is the full release of pgx 0.6.0!
Remember to rustup update and then cargo install cargo-pgx, but that also brings us to the first two updates!
It's important to remember to update your rustc installation first because the rustc version must be the same as what is used to build cargo pgx and for compiling crates. We now we enforce that thanks to thomcc.
You may now build cargo pgx with rustls thanks to @felipe-vaultree, using:

cargo install cargo-pgx \
  --locked \
  --version 0.6.0 \
  --features rustls

rustls can help if the "native TLS" cargo pgx would default to is OpenSSL.
This is not a comment on OpenSSL's security, only on ease of installing and using it.

New Logo!

Check it out! We added a new logo by Cenza Della Donna!

Logo

Breaking Changes

This version brings a number of breaking changes.

Postgres Major Support

This release introduces support for Postgres 15 and drops support for Postgres 10, thanks to @Smittyvb, @BradyBonnette, @yrashk, and @steve-chavez!

Numeric

Thanks to @eeeebbbbrrrr, proper support for SQL's NUMERIC has landed in PGX, using two types:

  • AnyNumeric
  • Numeric<const P: u32, const S: u32>

Obviously, this breaks code using Numeric as it currently is, which is more like AnyNumeric.

Usage Note: As far as we are able to discern, AnyNumeric is the type used by Postgres on SQL function entry and exit, even if you specify a precision and scale in SQL, so for the case of #[pg_extern] you should probably prefer AnyNumeric, and deliberately convert to Numeric<P, S> inside functions if needed. Numeric<P,S> helps most with serialization, writing to tables, and other cases Postgres also uses strict precision and scale.

Error Handling has been revamped

Error handling has been revamped in a way that may be breaking if you were directly handling PGX's error-handling functions, which are intended to be used when you extend this with your own error-handling abstractions. This includes a lot more support for the kinds of patterns allowed by PG_TRY and PG_CATCH. Take a look at PgTryBuilder.

SpiClient now discourages misuse, plus other Spi* improvements

@yrashk and @thomcc have significantly revised the way that SpiClient works, although a lot of users won't notice a difference. It now uses a scoped lifetime, existing as more of a consumable token, rather than something you can just arbitrarily instantiate. Also see:

  • Ensure SpiClient is only used within boundaries of a connection by @yrashk in #896
  • SpiClient::update no longer requires &mut self by @yrashk in #897
  • Non-leaking, consumable SpiClient by @yrashk in #898
  • Ensure the lifetime of SpiClient is scoped to the connection by @thomcc in #900

BackgroundWorker::transaction fixes

@yrashk expanded the ability of various contexts to allow data to escape them: background workers can return values from transaction, and no longer require Copy to do so.

PgNode is now sealed

This probably won't affect most users, but PgNode is now a "sealed trait", preventing you from implementing it on things. Sorry! PGX relies on the soundness of its implementation, and probably will rely on that more in the future.

PgRelation will promise less

Rust functions that are safe should not cause UB with arbitrary inputs, so @workingjubilee made PgRelation::with_lock unsafe in #886. Thanks to @JohnHVancouver for catching that one!

Deprecated code

Most deprecations that began in 0.5.0 have now been made good on:

  • Array::over is no more 🎉. This will allow us to speed up Array<'a, T> in the future and make it more sound.
  • Most of the ::new functions on datetime types.
    You can still opt in or out of the time crate as a dependency using
pgx = { version = "0.6.0", features = "time-crate" }

This will let you use various TryFrom or From impls.

typo lol

The indicies function now is indices thanks to @jteplitz. This is technically a breaking change!

New in 0.6.0

pgx::datum::Range<T>

We now can map "range types" between Rust and Postgres thanks to @mhov!

pgx now defends against FFI while multithreading

It's now almost reasonable to offload work onto multiple threads while using PGX, as @thomcc gave us a true check for calling FFI from multiple threads that is more resilient to being fooled by renaming threads or other oddness you might get up to. @eeeebbbbrrrr made pg_sys functions also #[track_caller] to help detect and track this. Remember, however, that Postgres is fundamentally single-threaded, so all interaction with Postgres must be on a single thread... and whether PGX functions call into Postgres may change between versions without warning!

  • Include caller location in error message when pgx detects a Postgres FFI was called on a not-the-main-thread by @eeeebbbbrrrr in #862
  • "ereport" messages (pgx::log!(), pgx::error!(), etc) no longer add a CONTEXT message to the ereport by @eeeebbbbrrrr in #875

pgx-pg-sys build improvements

Pertinent to our Postgres version support updates, @BradyBonnette taught pgx-pg-sys how to warn if you use an unsupported version of Postgres.

We also gained some bindings:

  • Include extension & namespace catalogs by @yrashk in #836
  • Add bindings for typedefs within replication/logical.h to pg_sys by @agamble in #827
  • add the catalog/indexing.h header by @eeeebbbbrrrr in #874

Compatibility with various environments

cargo pgx will now configure databases to use C.UTF-8 locale when it creates them (e.g. for testing) thanks to @Smittyvb, or use the "C" locale instead as a fallback.

/And we now also test multiple distros thanks to @BradyBonnette!

Thanks to @pcnc we caught some AArch64 compatibility issues related to c_char.

Miscellaneous Improvements

Most other changes are more subtle quality of life improvements:

Documentation and example updates

A fair amount of PGX documentation got some polish.

  • Update PgTryBuilder docs by @yrashk in #865
  • Provide an example of PostgresType derivation on enums by @yrashk in #861
  • Document pg_extern(name) by @yrashk in #868
  • Thanks to @MaxKingPor we found the macro docs still mentioned impl Iterator! It now recommends TableIterator appropriately. Please let us know if you find any issues with the PGX documentation or have a question!

New Contributors

Full Changelog: v0.5.6...v0.6.0

Don't miss a new pgrx release

NewReleases is sending notifications on new releases.