跳转到主要内容

pg_variables

提供标量、数组和记录类型的会话变量

pg_variables · 提供标量、数组和记录类型的会话变量

概览

ID扩展软件包版本类别许可证编程语言
2820pg_variablespg_variables1.2.5FEATPostgreSQLC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否
SQL 1.2. PG19 RPM uses a patch.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.2.519 18 17 16 15pg_variables-
RPMPIGSTY1.2.519 18 17 16 15pg_variables_$v-
DEBPIGSTY1.2.519 18 17 16 15postgresql-$v-pg-variables-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
el8.aarch64N/APIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
el9.x86_64PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
el9.aarch64PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
el10.x86_64PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
el10.aarch64PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
d12.x86_64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
d12.aarch64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
d13.x86_64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
d13.aarch64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
u22.x86_64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
u22.aarch64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
u24.x86_64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
u24.aarch64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
u26.x86_64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
u26.aarch64MISSPIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5PIGSTY 1.2.5
软件包版本平台仓库大小下载
pg_variables_191.2.5el9.x86_64pigsty72.7 KiBpg_variables_19-1.2.5-2PGSTY.el9.x86_64.rpm
pg_variables_191.2.5el9.aarch64pigsty72.1 KiBpg_variables_19-1.2.5-2PGSTY.el9.aarch64.rpm
pg_variables_191.2.5el10.x86_64pigsty73.4 KiBpg_variables_19-1.2.5-2PGSTY.el10.x86_64.rpm
pg_variables_191.2.5el10.aarch64pigsty73.0 KiBpg_variables_19-1.2.5-2PGSTY.el10.aarch64.rpm
软件包版本平台仓库大小下载
pg_variables_181.2.5el8.x86_64pigsty70.5 KiBpg_variables_18-1.2.5-2PGSTY.el8.x86_64.rpm
pg_variables_181.2.5el8.aarch64pigsty70.1 KiBpg_variables_18-1.2.5-2PGSTY.el8.aarch64.rpm
pg_variables_181.2.5el9.x86_64pigsty72.5 KiBpg_variables_18-1.2.5-2PGSTY.el9.x86_64.rpm
pg_variables_181.2.5el9.aarch64pigsty71.8 KiBpg_variables_18-1.2.5-2PGSTY.el9.aarch64.rpm
pg_variables_181.2.5el10.x86_64pigsty73.0 KiBpg_variables_18-1.2.5-2PGSTY.el10.x86_64.rpm
pg_variables_181.2.5el10.aarch64pigsty72.9 KiBpg_variables_18-1.2.5-2PGSTY.el10.aarch64.rpm
postgresql-18-pg-variables1.2.5d12.x86_64pigsty60.0 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~bookworm_amd64.deb
postgresql-18-pg-variables1.2.5d12.aarch64pigsty59.5 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~bookworm_arm64.deb
postgresql-18-pg-variables1.2.5d13.x86_64pigsty60.2 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~trixie_amd64.deb
postgresql-18-pg-variables1.2.5d13.aarch64pigsty59.7 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~trixie_arm64.deb
postgresql-18-pg-variables1.2.5u22.x86_64pigsty65.5 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~jammy_amd64.deb
postgresql-18-pg-variables1.2.5u22.aarch64pigsty65.4 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~jammy_arm64.deb
postgresql-18-pg-variables1.2.5u24.x86_64pigsty63.1 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~noble_amd64.deb
postgresql-18-pg-variables1.2.5u24.aarch64pigsty63.4 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~noble_arm64.deb
postgresql-18-pg-variables1.2.5u26.x86_64pigsty62.1 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~resolute_amd64.deb
postgresql-18-pg-variables1.2.5u26.aarch64pigsty62.5 KiBpostgresql-18-pg-variables_1.2.5-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_variables_171.2.5el8.x86_64pigsty70.4 KiBpg_variables_17-1.2.5-2PGSTY.el8.x86_64.rpm
pg_variables_171.2.5el8.aarch64pigsty70.0 KiBpg_variables_17-1.2.5-2PGSTY.el8.aarch64.rpm
pg_variables_171.2.5el9.x86_64pigsty72.3 KiBpg_variables_17-1.2.5-2PGSTY.el9.x86_64.rpm
pg_variables_171.2.5el9.aarch64pigsty71.7 KiBpg_variables_17-1.2.5-2PGSTY.el9.aarch64.rpm
pg_variables_171.2.5el10.x86_64pigsty72.8 KiBpg_variables_17-1.2.5-2PGSTY.el10.x86_64.rpm
pg_variables_171.2.5el10.aarch64pigsty72.8 KiBpg_variables_17-1.2.5-2PGSTY.el10.aarch64.rpm
postgresql-17-pg-variables1.2.5d12.x86_64pigsty59.8 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~bookworm_amd64.deb
postgresql-17-pg-variables1.2.5d12.aarch64pigsty59.8 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~bookworm_arm64.deb
postgresql-17-pg-variables1.2.5d13.x86_64pigsty60.0 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~trixie_amd64.deb
postgresql-17-pg-variables1.2.5d13.aarch64pigsty60.0 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~trixie_arm64.deb
postgresql-17-pg-variables1.2.5u22.x86_64pigsty71.1 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~jammy_amd64.deb
postgresql-17-pg-variables1.2.5u22.aarch64pigsty71.0 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~jammy_arm64.deb
postgresql-17-pg-variables1.2.5u24.x86_64pigsty63.0 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~noble_amd64.deb
postgresql-17-pg-variables1.2.5u24.aarch64pigsty63.6 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~noble_arm64.deb
postgresql-17-pg-variables1.2.5u26.x86_64pigsty61.9 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~resolute_amd64.deb
postgresql-17-pg-variables1.2.5u26.aarch64pigsty62.6 KiBpostgresql-17-pg-variables_1.2.5-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_variables_161.2.5el8.x86_64pigsty70.3 KiBpg_variables_16-1.2.5-2PGSTY.el8.x86_64.rpm
pg_variables_161.2.5el8.aarch64pigsty69.9 KiBpg_variables_16-1.2.5-2PGSTY.el8.aarch64.rpm
pg_variables_161.2.5el9.x86_64pigsty72.3 KiBpg_variables_16-1.2.5-2PGSTY.el9.x86_64.rpm
pg_variables_161.2.5el9.aarch64pigsty71.6 KiBpg_variables_16-1.2.5-2PGSTY.el9.aarch64.rpm
pg_variables_161.2.5el10.x86_64pigsty72.8 KiBpg_variables_16-1.2.5-2PGSTY.el10.x86_64.rpm
pg_variables_161.2.5el10.aarch64pigsty72.7 KiBpg_variables_16-1.2.5-2PGSTY.el10.aarch64.rpm
postgresql-16-pg-variables1.2.5d12.x86_64pigsty59.7 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~bookworm_amd64.deb
postgresql-16-pg-variables1.2.5d12.aarch64pigsty59.7 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~bookworm_arm64.deb
postgresql-16-pg-variables1.2.5d13.x86_64pigsty59.9 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~trixie_amd64.deb
postgresql-16-pg-variables1.2.5d13.aarch64pigsty59.9 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~trixie_arm64.deb
postgresql-16-pg-variables1.2.5u22.x86_64pigsty70.7 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~jammy_amd64.deb
postgresql-16-pg-variables1.2.5u22.aarch64pigsty70.7 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~jammy_arm64.deb
postgresql-16-pg-variables1.2.5u24.x86_64pigsty62.9 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~noble_amd64.deb
postgresql-16-pg-variables1.2.5u24.aarch64pigsty63.6 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~noble_arm64.deb
postgresql-16-pg-variables1.2.5u26.x86_64pigsty61.8 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~resolute_amd64.deb
postgresql-16-pg-variables1.2.5u26.aarch64pigsty62.6 KiBpostgresql-16-pg-variables_1.2.5-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_variables_151.2.5el8.x86_64pigsty70.3 KiBpg_variables_15-1.2.5-2PGSTY.el8.x86_64.rpm
pg_variables_151.2.5el8.aarch64pigsty69.8 KiBpg_variables_15-1.2.5-2PGSTY.el8.aarch64.rpm
pg_variables_151.2.5el9.x86_64pigsty72.2 KiBpg_variables_15-1.2.5-2PGSTY.el9.x86_64.rpm
pg_variables_151.2.5el9.aarch64pigsty71.7 KiBpg_variables_15-1.2.5-2PGSTY.el9.aarch64.rpm
pg_variables_151.2.5el10.x86_64pigsty72.6 KiBpg_variables_15-1.2.5-2PGSTY.el10.x86_64.rpm
pg_variables_151.2.5el10.aarch64pigsty72.7 KiBpg_variables_15-1.2.5-2PGSTY.el10.aarch64.rpm
postgresql-15-pg-variables1.2.5d12.x86_64pigsty59.7 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~bookworm_amd64.deb
postgresql-15-pg-variables1.2.5d12.aarch64pigsty59.4 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~bookworm_arm64.deb
postgresql-15-pg-variables1.2.5d13.x86_64pigsty59.8 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~trixie_amd64.deb
postgresql-15-pg-variables1.2.5d13.aarch64pigsty59.4 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~trixie_arm64.deb
postgresql-15-pg-variables1.2.5u22.x86_64pigsty70.6 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~jammy_amd64.deb
postgresql-15-pg-variables1.2.5u22.aarch64pigsty71.1 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~jammy_arm64.deb
postgresql-15-pg-variables1.2.5u24.x86_64pigsty62.7 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~noble_amd64.deb
postgresql-15-pg-variables1.2.5u24.aarch64pigsty63.1 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~noble_arm64.deb
postgresql-15-pg-variables1.2.5u26.x86_64pigsty61.8 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~resolute_amd64.deb
postgresql-15-pg-variables1.2.5u26.aarch64pigsty62.2 KiBpostgresql-15-pg-variables_1.2.5-2PGSTY~resolute_arm64.deb

源码

pig build pkg pg_variables;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_variables;		# install by package name

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

在数据库中创建扩展。

CREATE EXTENSION pg_variables;

用法

pg_variables 提供按名称 package 分组的会话级变量。变量只存在于当前 session;除非创建时指定 is_transactional := true,否则默认不参与事务。

基本读写

CREATE EXTENSION pg_variables;

SELECT pgv_set('vars', 'int1', 101);
SELECT pgv_get('vars', 'int1', NULL::int);

事务性变量会参与 savepoint 和 rollback:

BEGIN;
SELECT pgv_set('vars', 'trans_int', 101, true);
SAVEPOINT sp1;
SELECT pgv_set('vars', 'trans_int', 102, true);
ROLLBACK TO sp1;
COMMIT;

核心 API

README 记录了通用标量与数组 API:

  • pgv_set(package, name, value, is_transactional default false)
  • pgv_get(package, name, NULL::type, strict default true)

同时也记录了面向 record 的 API:

  • pgv_insert()
  • pgv_update()
  • pgv_delete()
  • pgv_select()

常用的管理辅助函数包括 pgv_exists()、pgv_remove()、pgv_free()、pgv_list() 和 pgv_stats()。

错误与 strict 行为

pgv_get() 会同时检查变量是否存在以及类型是否匹配。README 展示了 package 不存在、变量不存在或类型不匹配时会抛错;如果指定 strict := false,则在值缺失时返回 NULL。

已废弃辅助函数与版本说明

上游仍然提供一些已废弃的类型专用辅助函数,例如 pgv_set_int() / pgv_get_int() 和 pgv_set_jsonb() / pgv_get_jsonb(),但推荐使用通用的 pgv_set() / pgv_get()。

仓库 tag 已到 v1.2.5,而当前 pg_variables.control 仍声明 default_version = '1.2'。这与打包说明一致,即 release tag 已前进,但 SQL 扩展版本字符串没有同步变更。

表格阅读器