Repository navigation
v0.1.0
pgzx v0.1.0 - PostgreSQL extensions in Zig
pgzx is a library for building PostgreSQL extensions in Zig. It wraps the Postgres C API with idiomatic Zig utilities - error handling, memory allocators, function registration - and ships a development environment that makes building, installing, and testing extensions ergonomic.
This is the initial release. The API is broad and already proven by the bundled examples, but it is not stable: expect breaking changes between releases while the project is under active development.
Highlights
- SQL/DDL generation - describe your SQL objects in a comptime
pgzx_sqldeclaration and letzig buildrender the versioned extension script, deriving SQL types from your Zig signatures. - Function manager - register functions for SQL with
PG_FUNCTION_V1, with automatic (de)serialization of arguments viapgzx.datumconverters. - Error handling - idiomatic Zig wrappers over Postgres error reporting, plus
pgzx.err.Context/pg_tryfor error-safe FFI (a Zig-native alternative toPG_TRYthat keepsdefer/errdeferworking). - Memory context allocators - expose Postgres memory contexts as Zig
Allocators, with reset/delete callbacks. - Types & data structures - base and composite types, arrays (
[]T,text[],IntList/OidList),HeapTuple/TupleDesc, andslist/dlist/htabwrappers. - SPI - queries, cursors, prepared/saved plans, and subtransactions.
- GUCs -
DefineCustom*Variablewrappers with assign/show hooks. - Concurrency primitives - atomics, spinlocks, LWLocks, shared memory, and background workers.
- Operators, casts, opclasses - btree/hash opclasses so custom types are indexable and work with
GROUP BY. - Set-returning functions -
SetOf/Tableiterators withSETOF/TABLEDDL. - Testing - a reusable
PGBuildharness withpg_regressand in-server unit tests, plus anix flaketemplate to bootstrap a new extension.
Requirements
- Zig 0.17.0
- PostgreSQL 15 - 18 (PostgreSQL 14 is not yet supported)
Example extensions
A growing set of samples, ordered simple to complex, covering functions, custom types with opclasses, arrays, SPI, set-returning functions, GUCs, background workers, hooks, and backend-safe file I/O - see examples/.
Use this release
zig fetch --save=pgzx https://github.com/barddoo/pgzx/archive/refs/tags/v0.1.0.tar.gz
Package hash: pgzx-0.1.0-PsG6MNSEBwBroeMEwVm3CeTPD588lJoU8WFUaUAIPvys
Then add pgzx as a dependency in your build.zig.zon and import it from build.zig. See the reference docs for the full API.
Learn more
- Documentation: https://xataio.github.io/pgzx/
- Examples: https://github.com/barddoo/pgzx/tree/v0.1.0/examples
- Roadmap: https://github.com/barddoo/pgzx/blob/v0.1.0/ROADMAP.md
Full Changelog: https://github.com/barddoo/pgzx/commits/v0.1.0