pgx_ulid
ulid type and methods
Repository
pksunkara/pgx_ulid
https://github.com/pksunkara/pgx_ulid
Source
pgx_ulid-0.2.2.tar.gz
pgx_ulid-0.2.2.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pgx_ulid | 0.2.2 | FUNC | MIT | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4510 | pgx_ulid | No | Yes | Yes | Yes | No | No | - |
| Related | pg_idkit pg_uuidv7 sequential_uuids uuid-ossp pg_hashids permuteseq |
|---|
manual updated pgrx by Vonng
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.2.2 | 1817161514 | pgx_ulid | - |
| RPM | PIGSTY | 0.2.2 | 1817161514 | pgx_ulid_$v | - |
| DEB | PIGSTY | 0.2.2 | 1817161514 | postgresql-$v-pgx-ulid | - |
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
CREATE EXTENSION pgx_ulid;
ULID Type
The extension provides a native ulid type – a 26-character, lexicographically sortable identifier stored in binary.
Functions
| Function | Description |
|---|---|
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 ULIDtimestamp::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;
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.