pgx_ulid
ULID数据类型与函数
仓库
pksunkara/pgx_ulid
https://github.com/pksunkara/pgx_ulid
源码
pgx_ulid-0.2.3.tar.gz
pgx_ulid-0.2.3.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pgx_ulid | 0.2.3 | FUNC | MIT | Rust |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 4510 | pgx_ulid | 否 | 是 | 是 | 是 | 否 | 否 | - |
| 相关扩展 | 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.
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.2.3 | 1817161514 | pgx_ulid | - |
| RPM | PIGSTY | 0.2.3 | 1817161514 | pgx_ulid_$v | - |
| DEB | PIGSTY | 0.2.3 | 1817161514 | postgresql-$v-pgx-ulid | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.2.3 el8.x86_64.pg18 : pgx_ulid_18 pgx_ulid_18-0.2.3-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.2.3 el8.x86_64.pg17 : pgx_ulid_17 pgx_ulid_17-0.2.3-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.2.3 el8.x86_64.pg16 : pgx_ulid_16 pgx_ulid_16-0.2.3-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.2.3 el8.x86_64.pg15 : pgx_ulid_15 pgx_ulid_15-0.2.3-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.2.3 el8.x86_64.pg14 : pgx_ulid_14 pgx_ulid_14-0.2.3-1PIGSTY.el8.x86_64.rpm
|
| el8.aarch64 | PIGSTY 0.2.3 el8.aarch64.pg18 : pgx_ulid_18 pgx_ulid_18-0.2.3-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.2.3 el8.aarch64.pg17 : pgx_ulid_17 pgx_ulid_17-0.2.3-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.2.3 el8.aarch64.pg16 : pgx_ulid_16 pgx_ulid_16-0.2.3-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.2.3 el8.aarch64.pg15 : pgx_ulid_15 pgx_ulid_15-0.2.3-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.2.3 el8.aarch64.pg14 : pgx_ulid_14 pgx_ulid_14-0.2.3-1PIGSTY.el8.aarch64.rpm
|
| el9.x86_64 | PIGSTY 0.2.3 el9.x86_64.pg18 : pgx_ulid_18 pgx_ulid_18-0.2.3-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.2.3 el9.x86_64.pg17 : pgx_ulid_17 pgx_ulid_17-0.2.3-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.2.3 el9.x86_64.pg16 : pgx_ulid_16 pgx_ulid_16-0.2.3-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.2.3 el9.x86_64.pg15 : pgx_ulid_15 pgx_ulid_15-0.2.3-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.2.3 el9.x86_64.pg14 : pgx_ulid_14 pgx_ulid_14-0.2.3-1PIGSTY.el9.x86_64.rpm
|
| el9.aarch64 | PIGSTY 0.2.3 el9.aarch64.pg18 : pgx_ulid_18 pgx_ulid_18-0.2.3-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.2.3 el9.aarch64.pg17 : pgx_ulid_17 pgx_ulid_17-0.2.3-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.2.3 el9.aarch64.pg16 : pgx_ulid_16 pgx_ulid_16-0.2.3-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.2.3 el9.aarch64.pg15 : pgx_ulid_15 pgx_ulid_15-0.2.3-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.2.3 el9.aarch64.pg14 : pgx_ulid_14 pgx_ulid_14-0.2.3-1PIGSTY.el9.aarch64.rpm
|
| el10.x86_64 | PIGSTY 0.2.3 el10.x86_64.pg18 : pgx_ulid_18 pgx_ulid_18-0.2.3-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.2.3 el10.x86_64.pg17 : pgx_ulid_17 pgx_ulid_17-0.2.3-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.2.3 el10.x86_64.pg16 : pgx_ulid_16 pgx_ulid_16-0.2.3-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.2.3 el10.x86_64.pg15 : pgx_ulid_15 pgx_ulid_15-0.2.3-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.2.3 el10.x86_64.pg14 : pgx_ulid_14 pgx_ulid_14-0.2.3-1PIGSTY.el10.x86_64.rpm
|
| el10.aarch64 | PIGSTY 0.2.3 el10.aarch64.pg18 : pgx_ulid_18 pgx_ulid_18-0.2.3-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.2.3 el10.aarch64.pg17 : pgx_ulid_17 pgx_ulid_17-0.2.3-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.2.3 el10.aarch64.pg16 : pgx_ulid_16 pgx_ulid_16-0.2.3-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.2.3 el10.aarch64.pg15 : pgx_ulid_15 pgx_ulid_15-0.2.3-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.2.3 el10.aarch64.pg14 : pgx_ulid_14 pgx_ulid_14-0.2.3-1PIGSTY.el10.aarch64.rpm
|
| d12.x86_64 | PIGSTY 0.2.3 d12.x86_64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.2.3 d12.x86_64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.2.3 d12.x86_64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.2.3 d12.x86_64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.2.3 d12.x86_64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~bookworm_amd64.deb
|
| d12.aarch64 | PIGSTY 0.2.3 d12.aarch64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.2.3 d12.aarch64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.2.3 d12.aarch64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.2.3 d12.aarch64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.2.3 d12.aarch64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~bookworm_arm64.deb
|
| d13.x86_64 | PIGSTY 0.2.3 d13.x86_64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.2.3 d13.x86_64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.2.3 d13.x86_64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.2.3 d13.x86_64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.2.3 d13.x86_64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~trixie_amd64.deb
|
| d13.aarch64 | PIGSTY 0.2.3 d13.aarch64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.2.3 d13.aarch64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.2.3 d13.aarch64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.2.3 d13.aarch64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.2.3 d13.aarch64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~trixie_arm64.deb
|
| u22.x86_64 | PIGSTY 0.2.3 u22.x86_64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.2.3 u22.x86_64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.2.3 u22.x86_64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.2.3 u22.x86_64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.2.3 u22.x86_64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~jammy_amd64.deb
|
| u22.aarch64 | PIGSTY 0.2.3 u22.aarch64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.2.3 u22.aarch64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.2.3 u22.aarch64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.2.3 u22.aarch64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.2.3 u22.aarch64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~jammy_arm64.deb
|
| u24.x86_64 | PIGSTY 0.2.3 u24.x86_64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~noble_amd64.deb
| PIGSTY 0.2.3 u24.x86_64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~noble_amd64.deb
| PIGSTY 0.2.3 u24.x86_64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~noble_amd64.deb
| PIGSTY 0.2.3 u24.x86_64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~noble_amd64.deb
| PIGSTY 0.2.3 u24.x86_64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~noble_amd64.deb
|
| u24.aarch64 | PIGSTY 0.2.3 u24.aarch64.pg18 : postgresql-18-pgx-ulid postgresql-18-pgx-ulid_0.2.3-1PIGSTY~noble_arm64.deb
| PIGSTY 0.2.3 u24.aarch64.pg17 : postgresql-17-pgx-ulid postgresql-17-pgx-ulid_0.2.3-1PIGSTY~noble_arm64.deb
| PIGSTY 0.2.3 u24.aarch64.pg16 : postgresql-16-pgx-ulid postgresql-16-pgx-ulid_0.2.3-1PIGSTY~noble_arm64.deb
| PIGSTY 0.2.3 u24.aarch64.pg15 : postgresql-15-pgx-ulid postgresql-15-pgx-ulid_0.2.3-1PIGSTY~noble_arm64.deb
| PIGSTY 0.2.3 u24.aarch64.pg14 : postgresql-14-pgx-ulid postgresql-14-pgx-ulid_0.2.3-1PIGSTY~noble_arm64.deb
|
| u26.x86_64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u26.aarch64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
构建
您可以使用 pig build 命令构建 pgx_ulid 扩展的 RPM / DEB 包:
pig build pkg pgx_ulid # 构建 RPM / DEB 包
安装
您可以直接安装 pgx_ulid 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install pgx_ulid; # 当前活跃 PG 版本安装
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
预加载配置:
shared_preload_libraries = 'pgx_ulid';
创建扩展:
CREATE EXTENSION pgx_ulid;
用法
pgx_ulid 提供原生 ulid 类型、生成函数,以及与 timestamp 和 uuid 之间的类型转换。README 说明它以二进制形式存储,并支持 monotonic ULID。
启用扩展
CREATE EXTENSION ulid;
-- or CREATE EXTENSION pgx_ulid; if installed manually under that name
生成 ULID
SELECT gen_ulid();
SELECT gen_monotonic_ulid();
gen_monotonic_ulid() 需要:
shared_preload_libraries = 'pgx_ulid'
README 明确说明,这个 preload 要求只影响 gen_monotonic_ulid();扩展的其余部分无需预加载即可使用。
将 ulid 用作主键
CREATE TABLE users (
id ulid NOT NULL DEFAULT gen_ulid() PRIMARY KEY,
name text NOT NULL
);
SELECT * FROM users
WHERE id = '01ARZ3NDEKTSV4RRFFQ69G5FAV';
类型转换与范围查询
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;
README 还记录了 ulid 与 uuid 之间的双向 cast。
注意事项
- Monotonic ULID 通过 shared memory 和 LWLock 维护最近一次生成的值。
- README 提到 monotonic 生成在理论上可能发生溢出并报错,但实践中可视为极小概率事件。
- 截至 2026-04-19,上游当前版本为
v0.2.3,但没有单独发布该版本的面向用户说明。