pgx_ulid

ulid type and methods

Overview

PackageVersionCategoryLicenseLanguage
pgx_ulid0.2.2FUNCMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
4510pgx_ulidNoYesYesYesNoNo-
Relatedpg_idkit pg_uuidv7 sequential_uuids uuid-ossp pg_hashids permuteseq

manual updated pgrx by Vonng

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.2.21817161514pgx_ulid-
RPMPIGSTY0.2.21817161514pgx_ulid_$v-
DEBPIGSTY0.2.21817161514postgresql-$v-pgx-ulid-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
u22.x86_64
u22.aarch64
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
u24.x86_64
u24.aarch64
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2
PIGSTY 0.2.2

Build

You can build the RPM / DEB packages for pgx_ulid using pig build:

pig build pkg pgx_ulid         # build RPM / DEB packages

Install

You can install pgx_ulid directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pgx_ulid;          # Install for current active PG version
pig ext install -y pgx_ulid -v 18  # PG 18
pig ext install -y pgx_ulid -v 17  # PG 17
pig ext install -y pgx_ulid -v 16  # PG 16
pig ext install -y pgx_ulid -v 15  # PG 15
pig ext install -y pgx_ulid -v 14  # PG 14
dnf install -y pgx_ulid_18       # PG 18
dnf install -y pgx_ulid_17       # PG 17
dnf install -y pgx_ulid_16       # PG 16
dnf install -y pgx_ulid_15       # PG 15
dnf install -y pgx_ulid_14       # PG 14
apt install -y postgresql-18-pgx-ulid   # PG 18
apt install -y postgresql-17-pgx-ulid   # PG 17
apt install -y postgresql-16-pgx-ulid   # PG 16
apt install -y postgresql-15-pgx-ulid   # PG 15
apt install -y postgresql-14-pgx-ulid   # PG 14

Preload:

shared_preload_libraries = 'pgx_ulid';

Create Extension:

CREATE EXTENSION pgx_ulid;

Usage

pgx_ulid: ULID type and methods for PostgreSQL

CREATE EXTENSION pgx_ulid;

ULID Type

The extension provides a native ulid type – a 26-character, lexicographically sortable identifier stored in binary.

Functions

FunctionDescription
gen_ulid()Generate a new ULID
gen_monotonic_ulid()Generate monotonically increasing ULIDs (requires shared_preload_libraries)

Casting

  • ulid::timestamp – extract creation time from a ULID
  • timestamp::ulid – produce a ULID from a timestamp (zeroed random part)
  • ulid::uuid / uuid::ulid – convert between ULID and UUID

Examples

-- Use ULID as a primary key
CREATE TABLE users (
  id ulid NOT NULL DEFAULT gen_ulid() PRIMARY KEY,
  name text NOT NULL
);

-- Query by text representation
SELECT * FROM users WHERE id = '01ARZ3NDEKTSV4RRFFQ69G5FAV';

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

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

Last Modified 2026-03-12: add pg extension catalog (95749bf)