pg_etag
pg_etag · Fast ETag generation for rows and result sets using BLAKE2 hashes, with single-input functions and aggregates.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100592 | pg_etag | pg_etag | 1.0 | FUNC | BSD-3-Clause | C |
Usage
Sources:
pg_etag generates hexadecimal BLAKE2b digests for text, bytea, ordered result streams, and PostgreSQL large objects. Use those digests as application cache validators only after defining a stable serialization and row order.
Single Values and Rows
etag(text) and etag(bytea) return a 64-byte BLAKE2b digest as 128 lowercase hexadecimal characters. blake2(text, integer) and blake2(bytea, integer) let the caller select a digest length from 1 through 64 bytes; the implementation clamps values outside that interval.
Result-Set ETags
etag_agg(text) and etag_agg(bytea) hash the input bytes in aggregate order and ignore null inputs. Always put a deterministic ORDER BY inside the aggregate. The state function concatenates input bytes without adding a delimiter, so encode field and row boundaries in the hashed representation; otherwise different segmentations can produce the same byte stream.
Large Objects and Caveats
The overload public.etag(oid) hashes pg_largeobject.data pages ordered by page number. It requires access to the large object and is hard-coded into the public schema even though the control file says the extension is relocatable.
An ETag is only as stable as its serialization. Text formatting of timestamps, numerics, JSON, collations, or encodings can change across settings or versions. Hash canonical bytes, include every field that defines the representation, and remember that BLAKE2 collision resistance does not provide authentication or authorization. The extension depends on libb2.