ulid
ulid · Embedded pgrx ULID type, generators, and casts
Overview
PostgreSQL · 14, 15, 16
Usage
Sources:
ulid provides a binary PostgreSQL ULID type, ordinary and monotonic generators, ordering and hashing, plus implicit casts to UUID and timestamps. Use it for sortable 128-bit identifiers rendered as 26-character Crockford Base32 strings.
Core Workflow
Ordinary generation needs no preload setting.
To guarantee monotonic generation within the shared generator state, preload the library and restart PostgreSQL before calling gen_monotonic_ulid.
Main Objects
ulidis a 128-bit type with text input/output, comparison, hashing, and ordering support.gen_ulidcreates a new time-based identifier with a random component.gen_monotonic_ulidincrements the prior shared value when multiple IDs are generated in the same millisecond.ulid_from_uuidandulid_to_uuidback implicit casts betweenuuidandulid.ulid_to_timestampextracts the millisecond timestamp;timestamp_to_ulidproduces the lower bound whose random portion is zero.
Operational Notes
Only the monotonic generator depends on shared memory and takes an exclusive LWLock; the rest of the extension works without preloading. Monotonic overflow raises an error. Version 0.1.3 added timestamp-to-ULID casting, and the reviewed manifest exposes PostgreSQL 14, 15, and 16 build features. Test implicit-cast behavior in mixed uuid, ulid, and timestamp expressions so convenience casts do not hide unintended conversions.