Skip to content
pgx_ulid

pgx_ulid

pgx_ulid : ulid type and methods

Overview

ID Extension Package Version Category License Language
4510
pgx_ulid
pgx_ulid
0.2.3
FUNC
MIT
Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd--
No
Yes
Yes
Yes
no
no
Relationships
See Also
pg_idkit
pg_uuidv7
sequential_uuids
uuid-ossp
pg_hashids
permuteseq

shared_preload_libraries = pgx_ulid is only required for gen_monotonic_ulid(); other functions work without it.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.2.3
18
17
16
15
14
pgx_ulid -
RPM
PIGSTY
0.2.3
18
17
16
15
14
pgx_ulid_$v -
DEB
PIGSTY
0.2.3
18
17
16
15
14
postgresql-$v-pgx-ulid -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
el8.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
el9.x86_64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
el9.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
el10.x86_64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
el10.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
d12.x86_64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
d12.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
d13.x86_64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
d13.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
u22.x86_64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
u22.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
u24.x86_64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
u24.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
u26.x86_64
MISS
MISS
MISS
MISS
MISS
u26.aarch64
MISS
MISS
MISS
MISS
MISS
Package Version OS ORG SIZE File URL
pgx_ulid_18 0.2.3 el8.x86_64 pigsty 389.2 KiB pgx_ulid_18-0.2.3-1PIGSTY.el8.x86_64.rpm
pgx_ulid_18 0.2.3 el8.aarch64 pigsty 273.2 KiB pgx_ulid_18-0.2.3-1PIGSTY.el8.aarch64.rpm
pgx_ulid_18 0.2.3 el9.x86_64 pigsty 406.5 KiB pgx_ulid_18-0.2.3-1PIGSTY.el9.x86_64.rpm
pgx_ulid_18 0.2.3 el9.aarch64 pigsty 292.5 KiB pgx_ulid_18-0.2.3-1PIGSTY.el9.aarch64.rpm
pgx_ulid_18 0.2.3 el10.x86_64 pigsty 406.4 KiB pgx_ulid_18-0.2.3-1PIGSTY.el10.x86_64.rpm
pgx_ulid_18 0.2.3 el10.aarch64 pigsty 292.4 KiB pgx_ulid_18-0.2.3-1PIGSTY.el10.aarch64.rpm
postgresql-18-pgx-ulid 0.2.3 d12.x86_64 pigsty 322.2 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~bookworm_amd64.deb
postgresql-18-pgx-ulid 0.2.3 d12.aarch64 pigsty 213.3 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~bookworm_arm64.deb
postgresql-18-pgx-ulid 0.2.3 d13.x86_64 pigsty 322.2 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~trixie_amd64.deb
postgresql-18-pgx-ulid 0.2.3 d13.aarch64 pigsty 213.2 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~trixie_arm64.deb
postgresql-18-pgx-ulid 0.2.3 u22.x86_64 pigsty 363.4 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~jammy_amd64.deb
postgresql-18-pgx-ulid 0.2.3 u22.aarch64 pigsty 247.7 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~jammy_arm64.deb
postgresql-18-pgx-ulid 0.2.3 u24.x86_64 pigsty 360.1 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~noble_amd64.deb
postgresql-18-pgx-ulid 0.2.3 u24.aarch64 pigsty 246.0 KiB postgresql-18-pgx-ulid_0.2.3-1PIGSTY~noble_arm64.deb

Source

pig build pkg pgx_ulid;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pgx_ulid;		# install via package name, for the active PG version

pig install pgx_ulid -v 18;   # install for PG 18
pig install pgx_ulid -v 17;   # install for PG 17
pig install pgx_ulid -v 16;   # install for PG 16
pig install pgx_ulid -v 15;   # install for PG 15
pig install pgx_ulid -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pgx_ulid';

Create this extension with:

CREATE EXTENSION pgx_ulid;

Usage

Sources: README, releases

pgx_ulid provides a native ulid type, generators, and casts to and from timestamp and uuid. The README documents binary storage and monotonic ULID support.

Enable the extension

CREATE EXTENSION ulid;
-- or CREATE EXTENSION pgx_ulid; if installed manually under that name

Generate ULIDs

SELECT gen_ulid();
SELECT gen_monotonic_ulid();

gen_monotonic_ulid() needs:

shared_preload_libraries = 'pgx_ulid'

The README explicitly says this preload requirement only affects gen_monotonic_ulid(); the rest of the extension works without it.

Use ulid as a primary key

CREATE TABLE users (
  id ulid NOT NULL DEFAULT gen_ulid() PRIMARY KEY,
  name text NOT NULL
);

SELECT * FROM users
WHERE id = '01ARZ3NDEKTSV4RRFFQ69G5FAV';

Casts and range queries

ALTER TABLE users
ADD COLUMN created_at timestamp GENERATED ALWAYS AS (id::timestamp) STORED;

SELECT * FROM users
WHERE id BETWEEN '2023-09-15'::timestamp::ulid
            AND '2023-09-16'::timestamp::ulid;

The README also documents casts between ulid and uuid.

Caveats

  • Monotonic ULIDs use shared memory plus an LWLock to keep the last generated value.
  • The README notes that monotonic generation can theoretically overflow and raise an error, although it treats this as negligible in practice.
  • Release v0.2.3 is current upstream as of 2026-04-19, but upstream did not publish separate user-facing release notes for it.
Last updated on