跳转到主要内容

pg_protobuf

提供Protobuf函数支持

pg_protobuf · 提供Protobuf函数支持

概览

ID扩展软件包版本类别许可证编程语言
4120pg_protobufpg_protobuf1.0UTILMITC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.019 18 17 16 15pg_protobuf-
RPMPIGSTY1.019 18 17 16 15pg_protobuf_$v-
DEBPIGSTY1.019 18 17 16 15postgresql-$v-pg-protobuf-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el8.aarch64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
软件包版本平台仓库大小下载
pg_protobuf_191.0el9.x86_64pigsty50.0 KiBpg_protobuf_19-1.0-1PGSTY.el9.x86_64.rpm
pg_protobuf_191.0el9.aarch64pigsty49.6 KiBpg_protobuf_19-1.0-1PGSTY.el9.aarch64.rpm
pg_protobuf_191.0el10.x86_64pigsty50.5 KiBpg_protobuf_19-1.0-1PGSTY.el10.x86_64.rpm
pg_protobuf_191.0el10.aarch64pigsty50.1 KiBpg_protobuf_19-1.0-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-protobuf1.0d12.x86_64pigsty41.1 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-protobuf1.0d12.aarch64pigsty41.8 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-protobuf1.0d13.x86_64pigsty41.0 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~trixie_amd64.deb
postgresql-19-pg-protobuf1.0d13.aarch64pigsty41.9 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~trixie_arm64.deb
postgresql-19-pg-protobuf1.0u22.x86_64pigsty45.1 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~jammy_amd64.deb
postgresql-19-pg-protobuf1.0u22.aarch64pigsty44.9 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~jammy_arm64.deb
postgresql-19-pg-protobuf1.0u24.x86_64pigsty43.1 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~noble_amd64.deb
postgresql-19-pg-protobuf1.0u24.aarch64pigsty43.3 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~noble_arm64.deb
postgresql-19-pg-protobuf1.0u26.x86_64pigsty43.9 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~resolute_amd64.deb
postgresql-19-pg-protobuf1.0u26.aarch64pigsty43.5 KiBpostgresql-19-pg-protobuf_1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_protobuf_181.0el8.x86_64pigsty47.8 KiBpg_protobuf_18-1.0-1PGSTY.el8.x86_64.rpm
pg_protobuf_181.0el8.aarch64pigsty48.4 KiBpg_protobuf_18-1.0-1PGSTY.el8.aarch64.rpm
pg_protobuf_181.0el9.x86_64pigsty49.6 KiBpg_protobuf_18-1.0-1PGSTY.el9.x86_64.rpm
pg_protobuf_181.0el9.aarch64pigsty49.1 KiBpg_protobuf_18-1.0-1PGSTY.el9.aarch64.rpm
pg_protobuf_181.0el10.x86_64pigsty50.0 KiBpg_protobuf_18-1.0-1PGSTY.el10.x86_64.rpm
pg_protobuf_181.0el10.aarch64pigsty49.5 KiBpg_protobuf_18-1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-protobuf1.0d12.x86_64pigsty40.7 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-protobuf1.0d12.aarch64pigsty41.4 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-protobuf1.0d13.x86_64pigsty40.7 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-protobuf1.0d13.aarch64pigsty41.6 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-protobuf1.0u22.x86_64pigsty44.8 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-protobuf1.0u22.aarch64pigsty44.6 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-protobuf1.0u24.x86_64pigsty42.7 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-protobuf1.0u24.aarch64pigsty42.8 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-protobuf1.0u26.x86_64pigsty43.5 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-protobuf1.0u26.aarch64pigsty43.1 KiBpostgresql-18-pg-protobuf_1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_protobuf_171.0el8.x86_64pigsty47.2 KiBpg_protobuf_17-1.0-1PGSTY.el8.x86_64.rpm
pg_protobuf_171.0el8.aarch64pigsty47.8 KiBpg_protobuf_17-1.0-1PGSTY.el8.aarch64.rpm
pg_protobuf_171.0el9.x86_64pigsty49.2 KiBpg_protobuf_17-1.0-1PGSTY.el9.x86_64.rpm
pg_protobuf_171.0el9.aarch64pigsty48.6 KiBpg_protobuf_17-1.0-1PGSTY.el9.aarch64.rpm
pg_protobuf_171.0el10.x86_64pigsty49.1 KiBpg_protobuf_17-1.0-1PGSTY.el10.x86_64.rpm
pg_protobuf_171.0el10.aarch64pigsty48.8 KiBpg_protobuf_17-1.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-protobuf1.0d12.x86_64pigsty40.0 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-protobuf1.0d12.aarch64pigsty40.9 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-protobuf1.0d13.x86_64pigsty40.0 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-protobuf1.0d13.aarch64pigsty40.9 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-protobuf1.0u22.x86_64pigsty45.0 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-protobuf1.0u22.aarch64pigsty44.9 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-protobuf1.0u24.x86_64pigsty42.0 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-protobuf1.0u24.aarch64pigsty42.2 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-protobuf1.0u26.x86_64pigsty42.9 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-protobuf1.0u26.aarch64pigsty42.5 KiBpostgresql-17-pg-protobuf_1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_protobuf_161.0el8.x86_64pigsty47.0 KiBpg_protobuf_16-1.0-1PGSTY.el8.x86_64.rpm
pg_protobuf_161.0el8.aarch64pigsty47.6 KiBpg_protobuf_16-1.0-1PGSTY.el8.aarch64.rpm
pg_protobuf_161.0el9.x86_64pigsty48.5 KiBpg_protobuf_16-1.0-1PGSTY.el9.x86_64.rpm
pg_protobuf_161.0el9.aarch64pigsty48.5 KiBpg_protobuf_16-1.0-1PGSTY.el9.aarch64.rpm
pg_protobuf_161.0el10.x86_64pigsty48.9 KiBpg_protobuf_16-1.0-1PGSTY.el10.x86_64.rpm
pg_protobuf_161.0el10.aarch64pigsty48.6 KiBpg_protobuf_16-1.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-protobuf1.0d12.x86_64pigsty39.9 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-protobuf1.0d12.aarch64pigsty40.6 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-protobuf1.0d13.x86_64pigsty39.8 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-protobuf1.0d13.aarch64pigsty40.7 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-protobuf1.0u22.x86_64pigsty44.8 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-protobuf1.0u22.aarch64pigsty44.6 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-protobuf1.0u24.x86_64pigsty42.2 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-protobuf1.0u24.aarch64pigsty42.0 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-protobuf1.0u26.x86_64pigsty42.5 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-protobuf1.0u26.aarch64pigsty42.3 KiBpostgresql-16-pg-protobuf_1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_protobuf_151.0el8.x86_64pigsty45.7 KiBpg_protobuf_15-1.0-1PGSTY.el8.x86_64.rpm
pg_protobuf_151.0el8.aarch64pigsty45.9 KiBpg_protobuf_15-1.0-1PGSTY.el8.aarch64.rpm
pg_protobuf_151.0el9.x86_64pigsty47.0 KiBpg_protobuf_15-1.0-1PGSTY.el9.x86_64.rpm
pg_protobuf_151.0el9.aarch64pigsty46.9 KiBpg_protobuf_15-1.0-1PGSTY.el9.aarch64.rpm
pg_protobuf_151.0el10.x86_64pigsty47.3 KiBpg_protobuf_15-1.0-1PGSTY.el10.x86_64.rpm
pg_protobuf_151.0el10.aarch64pigsty47.5 KiBpg_protobuf_15-1.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-protobuf1.0d12.x86_64pigsty38.8 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-protobuf1.0d12.aarch64pigsty39.5 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-protobuf1.0d13.x86_64pigsty38.7 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-protobuf1.0d13.aarch64pigsty39.6 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-protobuf1.0u22.x86_64pigsty43.7 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-protobuf1.0u22.aarch64pigsty43.7 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-protobuf1.0u24.x86_64pigsty40.7 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-protobuf1.0u24.aarch64pigsty41.1 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-protobuf1.0u26.x86_64pigsty40.8 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-protobuf1.0u26.aarch64pigsty41.3 KiBpostgresql-15-pg-protobuf_1.0-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_protobuf;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_protobuf;		# install by package name

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

在数据库中创建扩展。

CREATE EXTENSION pg_protobuf;

用法

pg_protobuf: PostgreSQL 的 Protocol Buffers 支持

该扩展提供无需 schema 定义即可在 SQL 中直接解码 Protocol Buffer 二进制数据的函数。

函数

  • protobuf_decode(bytea) RETURNS cstring – 将 protobuf 二进制数据解码为可读格式
  • protobuf_get_int(bytea, int) RETURNS bigint – 按字段编号提取整数字段
  • protobuf_get_string(bytea, int) RETURNS text – 按字段编号提取字符串字段
  • protobuf_get_bytes(bytea, int) RETURNS bytea – 按字段编号提取原始字节
  • protobuf_get_bool(bytea, int) RETURNS boolean – 按字段编号提取布尔字段
  • protobuf_get_float(bytea, int) RETURNS real – 按字段编号提取浮点字段
  • protobuf_get_double(bytea, int) RETURNS double precision – 按字段编号提取双精度字段
  • protobuf_get_sfixed32(bytea, int) RETURNS int – 提取有符号定长 32 位字段
  • protobuf_get_sfixed64(bytea, int) RETURNS bigint – 提取有符号定长 64 位字段
  • protobuf_get_int_multi(bytea, int) RETURNS bigint[] – 提取重复整数字段
  • protobuf_get_string_multi(bytea, int) RETURNS text[] – 提取重复字符串字段
  • protobuf_get_bytes_multi(bytea, int) RETURNS bytea[] – 提取重复字节字段
  • protobuf_get_bool_multi(bytea, int) RETURNS boolean[] – 提取重复布尔字段
  • protobuf_get_float_multi(bytea, int) RETURNS real[] – 提取重复浮点字段
  • protobuf_get_double_multi(bytea, int) RETURNS double precision[] – 提取重复双精度字段
  • protobuf_get_sfixed32_multi(bytea, int) RETURNS int[] – 提取重复 sfixed32 字段
  • protobuf_get_sfixed64_multi(bytea, int) RETURNS bigint[] – 提取重复 sfixed64 字段

示例

CREATE EXTENSION pg_protobuf;

-- 创建包含 protobuf 数据的表
CREATE TABLE heroes (x bytea);

-- 为特定字段定义访问函数
CREATE FUNCTION hero_name(x bytea) RETURNS text AS $$
BEGIN
  RETURN protobuf_get_string(x, 512);
END $$ LANGUAGE plpgsql IMMUTABLE;

CREATE FUNCTION hero_hp(x bytea) RETURNS bigint AS $$
BEGIN
  RETURN protobuf_get_int(x, 2);
END $$ LANGUAGE plpgsql IMMUTABLE;

-- 在 protobuf 字段上创建索引
CREATE INDEX hero_name_idx ON heroes USING btree(hero_name(x));

-- 按 protobuf 字段查询
SELECT hero_name(x) FROM heroes ORDER BY hero_name(x) LIMIT 10;

限制

  • 不支持修改 Protobuf 数据
  • 枚举值可通过 protobuf_get_int 读取
  • 不直接支持无符号类型(PostgreSQL 中没有无符号整数)
  • *_multi 函数不支持 [packed=true](可改用 protobuf_get_bytes*)

表格阅读器