Skip to content
pgx_ulid

pgx_ulid

pgx_ulid : ulid type and methods

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4510
pgx_ulid
pgx_ulid
0.2.3
FUNC
MIT
Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--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

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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 / PGPG18PG17PG16PG15PG14
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
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PackageVersionOSORGSIZEFile URL
pgx_ulid_180.2.3el8.x86_64pigsty389.2 KiBpgx_ulid_18-0.2.3-1PIGSTY.el8.x86_64.rpm
pgx_ulid_180.2.3el8.aarch64pigsty273.2 KiBpgx_ulid_18-0.2.3-1PIGSTY.el8.aarch64.rpm
pgx_ulid_180.2.3el9.x86_64pigsty406.5 KiBpgx_ulid_18-0.2.3-1PIGSTY.el9.x86_64.rpm
pgx_ulid_180.2.3el9.aarch64pigsty292.5 KiBpgx_ulid_18-0.2.3-1PIGSTY.el9.aarch64.rpm
pgx_ulid_180.2.3el10.x86_64pigsty406.4 KiBpgx_ulid_18-0.2.3-1PIGSTY.el10.x86_64.rpm
pgx_ulid_180.2.3el10.aarch64pigsty292.4 KiBpgx_ulid_18-0.2.3-1PIGSTY.el10.aarch64.rpm
postgresql-18-pgx-ulid0.2.3d12.x86_64pigsty322.2 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~bookworm_amd64.deb
postgresql-18-pgx-ulid0.2.3d12.aarch64pigsty213.3 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~bookworm_arm64.deb
postgresql-18-pgx-ulid0.2.3d13.x86_64pigsty322.2 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~trixie_amd64.deb
postgresql-18-pgx-ulid0.2.3d13.aarch64pigsty213.2 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~trixie_arm64.deb
postgresql-18-pgx-ulid0.2.3u22.x86_64pigsty363.4 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~jammy_amd64.deb
postgresql-18-pgx-ulid0.2.3u22.aarch64pigsty247.7 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~jammy_arm64.deb
postgresql-18-pgx-ulid0.2.3u24.x86_64pigsty360.1 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~noble_amd64.deb
postgresql-18-pgx-ulid0.2.3u24.aarch64pigsty246.0 KiBpostgresql-18-pgx-ulid_0.2.3-1PIGSTY~noble_arm64.deb
postgresql-18-pgx-ulid0.2.3u26.aarch64pigsty222.7 KiBpostgresql-18-pgx-ulid_0.2.3-2PIGSTY~resolute_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. The pgext catalog tracks package and extension name pgx_ulid, version 0.2.3, for PostgreSQL 14-18.

Enable the extension

CREATE EXTENSION pgx_ulid;

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.
  • The upstream README also shows CREATE EXTENSION ulid; this stub follows db/extension.csv, where the package and lead extension are both pgx_ulid.
  • The GitHub release page lists v0.2.3 as latest and only labels it Release 0.2.3, with no separate user-facing release notes.
Last updated on