跳转到主要内容

pg_lexo

用于列表插入与重排的字典序位置类型

pg_lexo · 用于列表插入与重排的字典序位置类型

概览

ID扩展软件包版本类别许可证编程语言
3530pg_lexopg_lexo0.6.0TYPEMITRust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d--否是否是否否
Release/package 0.6.1 ships SQL/control version 0.6.0. Objects use the chosen installation schema; the old lexo schema was removed. superuser=false is not trusted=true. PGSTY patches lexo_next for native-type ordering and empty tables, and lexo_rebalance to preserve order independently of text collation.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.6.019 18 17 16 15pg_lexo-
RPMPIGSTY0.6.119 18 17 16 15pg_lexo_$v-
DEBPIGSTY0.6.119 18 17 16 15postgresql-$v-pg-lexo-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
el8.aarch64N/APIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
el9.x86_64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
el9.aarch64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
el10.x86_64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
el10.aarch64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
d12.x86_64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
d12.aarch64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
d13.x86_64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
d13.aarch64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
u22.x86_64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
u22.aarch64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
u24.x86_64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
u24.aarch64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
u26.x86_64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
u26.aarch64PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1PIGSTY 0.6.1N/A
软件包版本平台仓库大小下载
pg_lexo_190.6.1el9.x86_64pigsty934.0 KiBpg_lexo_19-0.6.1-2PGSTY.el9.x86_64.rpm
pg_lexo_190.6.1el9.aarch64pigsty902.1 KiBpg_lexo_19-0.6.1-2PGSTY.el9.aarch64.rpm
pg_lexo_190.6.1el10.x86_64pigsty934.3 KiBpg_lexo_19-0.6.1-2PGSTY.el10.x86_64.rpm
pg_lexo_190.6.1el10.aarch64pigsty903.0 KiBpg_lexo_19-0.6.1-2PGSTY.el10.aarch64.rpm
postgresql-19-pg-lexo0.6.1d12.x86_64pigsty634.9 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~bookworm_amd64.deb
postgresql-19-pg-lexo0.6.1d12.aarch64pigsty554.8 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~bookworm_arm64.deb
postgresql-19-pg-lexo0.6.1d13.x86_64pigsty635.2 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~trixie_amd64.deb
postgresql-19-pg-lexo0.6.1d13.aarch64pigsty555.2 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~trixie_arm64.deb
postgresql-19-pg-lexo0.6.1u22.x86_64pigsty705.7 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~jammy_amd64.deb
postgresql-19-pg-lexo0.6.1u22.aarch64pigsty655.2 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~jammy_arm64.deb
postgresql-19-pg-lexo0.6.1u24.x86_64pigsty691.6 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~noble_amd64.deb
postgresql-19-pg-lexo0.6.1u24.aarch64pigsty650.5 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~noble_arm64.deb
postgresql-19-pg-lexo0.6.1u26.x86_64pigsty688.5 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~resolute_amd64.deb
postgresql-19-pg-lexo0.6.1u26.aarch64pigsty648.1 KiBpostgresql-19-pg-lexo_0.6.1-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_lexo_180.6.1el8.x86_64pigsty378.5 KiBpg_lexo_18-0.6.1-1PGSTY.el8.x86_64.rpm
pg_lexo_180.6.1el8.aarch64pigsty265.6 KiBpg_lexo_18-0.6.1-1PGSTY.el8.aarch64.rpm
pg_lexo_180.6.1el9.x86_64pigsty928.3 KiBpg_lexo_18-0.6.1-2PGSTY.el9.x86_64.rpm
pg_lexo_180.6.1el9.aarch64pigsty896.3 KiBpg_lexo_18-0.6.1-2PGSTY.el9.aarch64.rpm
pg_lexo_180.6.1el10.x86_64pigsty929.7 KiBpg_lexo_18-0.6.1-2PGSTY.el10.x86_64.rpm
pg_lexo_180.6.1el10.aarch64pigsty896.9 KiBpg_lexo_18-0.6.1-2PGSTY.el10.aarch64.rpm
postgresql-18-pg-lexo0.6.1d12.x86_64pigsty632.3 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~bookworm_amd64.deb
postgresql-18-pg-lexo0.6.1d12.aarch64pigsty553.3 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~bookworm_arm64.deb
postgresql-18-pg-lexo0.6.1d13.x86_64pigsty632.5 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~trixie_amd64.deb
postgresql-18-pg-lexo0.6.1d13.aarch64pigsty553.5 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~trixie_arm64.deb
postgresql-18-pg-lexo0.6.1u22.x86_64pigsty703.1 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~jammy_amd64.deb
postgresql-18-pg-lexo0.6.1u22.aarch64pigsty654.0 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~jammy_arm64.deb
postgresql-18-pg-lexo0.6.1u24.x86_64pigsty693.6 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~noble_amd64.deb
postgresql-18-pg-lexo0.6.1u24.aarch64pigsty648.6 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~noble_arm64.deb
postgresql-18-pg-lexo0.6.1u26.x86_64pigsty685.2 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~resolute_amd64.deb
postgresql-18-pg-lexo0.6.1u26.aarch64pigsty646.8 KiBpostgresql-18-pg-lexo_0.6.1-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_lexo_170.6.1el8.x86_64pigsty378.4 KiBpg_lexo_17-0.6.1-1PGSTY.el8.x86_64.rpm
pg_lexo_170.6.1el8.aarch64pigsty265.6 KiBpg_lexo_17-0.6.1-1PGSTY.el8.aarch64.rpm
pg_lexo_170.6.1el9.x86_64pigsty923.7 KiBpg_lexo_17-0.6.1-2PGSTY.el9.x86_64.rpm
pg_lexo_170.6.1el9.aarch64pigsty894.5 KiBpg_lexo_17-0.6.1-2PGSTY.el9.aarch64.rpm
pg_lexo_170.6.1el10.x86_64pigsty924.8 KiBpg_lexo_17-0.6.1-2PGSTY.el10.x86_64.rpm
pg_lexo_170.6.1el10.aarch64pigsty895.1 KiBpg_lexo_17-0.6.1-2PGSTY.el10.aarch64.rpm
postgresql-17-pg-lexo0.6.1d12.x86_64pigsty631.3 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~bookworm_amd64.deb
postgresql-17-pg-lexo0.6.1d12.aarch64pigsty551.3 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~bookworm_arm64.deb
postgresql-17-pg-lexo0.6.1d13.x86_64pigsty630.2 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~trixie_amd64.deb
postgresql-17-pg-lexo0.6.1d13.aarch64pigsty551.6 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~trixie_arm64.deb
postgresql-17-pg-lexo0.6.1u22.x86_64pigsty700.2 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~jammy_amd64.deb
postgresql-17-pg-lexo0.6.1u22.aarch64pigsty650.5 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~jammy_arm64.deb
postgresql-17-pg-lexo0.6.1u24.x86_64pigsty690.6 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~noble_amd64.deb
postgresql-17-pg-lexo0.6.1u24.aarch64pigsty645.8 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~noble_arm64.deb
postgresql-17-pg-lexo0.6.1u26.x86_64pigsty682.3 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~resolute_amd64.deb
postgresql-17-pg-lexo0.6.1u26.aarch64pigsty644.6 KiBpostgresql-17-pg-lexo_0.6.1-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_lexo_160.6.1el8.x86_64pigsty378.4 KiBpg_lexo_16-0.6.1-1PGSTY.el8.x86_64.rpm
pg_lexo_160.6.1el8.aarch64pigsty265.6 KiBpg_lexo_16-0.6.1-1PGSTY.el8.aarch64.rpm
pg_lexo_160.6.1el9.x86_64pigsty921.6 KiBpg_lexo_16-0.6.1-2PGSTY.el9.x86_64.rpm
pg_lexo_160.6.1el9.aarch64pigsty888.5 KiBpg_lexo_16-0.6.1-2PGSTY.el9.aarch64.rpm
pg_lexo_160.6.1el10.x86_64pigsty921.9 KiBpg_lexo_16-0.6.1-2PGSTY.el10.x86_64.rpm
pg_lexo_160.6.1el10.aarch64pigsty889.2 KiBpg_lexo_16-0.6.1-2PGSTY.el10.aarch64.rpm
postgresql-16-pg-lexo0.6.1d12.x86_64pigsty628.7 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~bookworm_amd64.deb
postgresql-16-pg-lexo0.6.1d12.aarch64pigsty550.5 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~bookworm_arm64.deb
postgresql-16-pg-lexo0.6.1d13.x86_64pigsty628.7 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~trixie_amd64.deb
postgresql-16-pg-lexo0.6.1d13.aarch64pigsty550.6 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~trixie_arm64.deb
postgresql-16-pg-lexo0.6.1u22.x86_64pigsty698.9 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~jammy_amd64.deb
postgresql-16-pg-lexo0.6.1u22.aarch64pigsty649.2 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~jammy_arm64.deb
postgresql-16-pg-lexo0.6.1u24.x86_64pigsty690.1 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~noble_amd64.deb
postgresql-16-pg-lexo0.6.1u24.aarch64pigsty645.4 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~noble_arm64.deb
postgresql-16-pg-lexo0.6.1u26.x86_64pigsty681.6 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~resolute_amd64.deb
postgresql-16-pg-lexo0.6.1u26.aarch64pigsty642.5 KiBpostgresql-16-pg-lexo_0.6.1-2PGSTY~resolute_arm64.deb

源码

pig build pkg pg_lexo;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install pg_lexo;		# install by package name

pig install pg_lexo -v 19;   # install for PG 19
pig install pg_lexo -v 18;   # install for PG 18
pig install pg_lexo -v 17;   # install for PG 17
pig install pg_lexo -v 16;   # install for PG 16

在数据库中创建扩展。

CREATE EXTENSION pg_lexo;

用法

来源:

pg_lexo 0.6.0 提供 Base62 lexo 类型,用于稳定的用户可控排序。它可以在已有位置之前、之后或之间生成短值,使项目移动时不必重新编号全部行。该类型提供比较操作符,以及默认 B-tree 和哈希操作符类。

核心流程

CREATE EXTENSION pg_lexo;

CREATE TABLE items (
    id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    title text NOT NULL,
    position lexo NOT NULL UNIQUE DEFERRABLE
);

INSERT INTO items (title, position)
VALUES ('first', lexo_first());

INSERT INTO items (title, position)
SELECT 'last', lexo_after(position)
FROM items ORDER BY position DESC LIMIT 1;

INSERT INTO items (title, position)
VALUES ('middle', lexo_between('H'::lexo, 'I'::lexo));

SELECT * FROM items ORDER BY position;

lexo_first() 从 H 开始。lexo_after(lexo)、lexo_before(lexo) 和 lexo_between(lexo, lexo) 生成相邻位置;lexo_between 的任一参数可以为 NULL,表示开放的一端。输入只能包含 0-9、A-Z 和 a-z,其 ASCII 顺序与该类型的排序一致。

表辅助函数

lexo_next(table, position_column, key_column, key_value) 查找当前最大值并返回下一个位置,可选限定到某个分组。lexo_add_column(table, column) 添加 lexo 列。lexo_rebalance(table, position_column, key_column, key_value) 用均匀分布的位置重写匹配行,并返回更新行数。

这些辅助函数执行动态 SQL,调用者必须拥有相应表权限。重平衡会更新每条选中行,应与应用写入协调执行。如果位置列有唯一约束,应使用可延迟约束,并在重平衡事务中延迟检查,允许更新过程中出现临时重叠。位置生成本身不会预留值:并发会话可能得到相同位置,因此应建立合适的唯一约束,并在冲突时重试或串行化移动。当相邻位置之间(或最小值之前)没有可用 Base62 值时,应先重平衡。

0.6 版本边界

0.6 版移除了专用 lexo 模式。原来的 lexo.lexorank 类型改名为 lexo,lexo.first() 等模式限定函数改为 lexo_first() 等名称。旧示例必须迁移后才能使用。发行包版本 0.6.1 保留 SQL/control 版本 0.6.0,通过 pgrx 0.16.1 面向 PostgreSQL 16–18。Pigsty 软件包为 lexo_next 添加补丁,使用原生排序替代不存在的 max(lexo) 聚合,并让 lexo_rebalance 的顺序不受文本排序规则影响。

表格阅读器