pg_bech32
pg_bech32 · Adds Bech32, Bech32m, and no-checksum Bech32 encoding/decoding support to PostgreSQL.
Overview
PostgreSQL · 11, 12, 13, 14, 15, 16
Usage
Sources:
- Pinned upstream README
- Pinned Rust SQL implementation
- Pinned Rust package manifest
- Pinned extension control template
pg_bech32 version 0.0.0 adds Bech32, Bech32m, and checksum-free Bech32 encoding to PostgreSQL, plus decoding for checksummed Bech32 strings. It accepts binary payloads as bytea and returns decoded data together with the human-readable prefix.
Core Workflow
Important Objects
bech32_encode(hrp, bytea, mode): encodes with modebech32,bech32m, ornochecksum.bech32_encode_lower(hrp, bytea, mode): produces a lower-case encoded string using the same modes.bech32_decode(text): validates and decodes a checksummed Bech32 or Bech32m string.- Composite type
bech32: contains fieldshrp textanddata bytea; the unquoted upstream type declaration is folded to lower case by PostgreSQL.
Operational Notes
The decoder does not return which checksum variant was used, and the documented decoder path is for checksummed Bech32/Bech32m rather than nochecksum; keep protocol/version context outside the value. Invalid HRPs, strings, checksums, or mode names raise errors from the Rust implementation. The control template marks installation as superuser-only and non-relocatable.
The Cargo feature matrix targets PostgreSQL 11–16 using pgrx 0.11.3; later PostgreSQL releases are not confirmed by this revision. Version 0.0.0 and the minimal upstream documentation indicate an early project surface, so verify canonical casing, maximum lengths, protocol-specific witness/version rules, and round trips with authoritative test vectors before using encoded values as durable identifiers.