跳转到主要内容

omni_json

Omnigres JSON工具箱

omnigres · Omnigres JSON工具箱

概览

ID扩展软件包版本类别许可证编程语言
2953omni_jsonomnigres0.1.1FEATApache-2.0C
属性可执行文件动态库需要预加载需要建扩展可迁移可信
----dt-否否否是否是

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.1.119 18 17 16 15omnigres-
RPMPIGSTY2026021219 18 17 16 15omnigres_$vpostgresql$v-contrib, postgresql$v-plpython3, python3-pip
DEBPIGSTY2026021219 18 17 16 15postgresql-$v-omnigrespostgresql-plpython3-$v, python3-pip
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el8.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el9.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el9.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el10.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el10.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d12.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d12.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d13.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d13.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u22.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u22.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u24.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u24.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u26.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u26.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212

源码

pig build pkg omnigres;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install omnigres;		# install by package name
pig install omni_json;		# install by extension name

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

在数据库中创建扩展。

CREATE EXTENSION omni_json;

用法

omni_json: JSON 工具箱

omni_json 扩展提供表到 JSON 的映射功能,支持在行转换为 JSON 时进行自定义变换。

定义表映射

SELECT omni_json.define_table_mapping(example, '{}');

列重命名

SELECT omni_json.define_table_mapping(example, '{
    "columns": { "dob": { "path": "date_of_birth" } }
}');

嵌套键

SELECT omni_json.define_table_mapping(example, '{
    "columns": {
        "first_name": { "path": ["name", "first"] },
        "last_name":  { "path": ["name", "last"] }
    }
}');

列排除

SELECT omni_json.define_table_mapping(example, '{
    "columns": { "dob": { "exclude": true } }
}');

列变换

输入(JSON 到记录)和输出(记录到 JSON)变换:

{
    "columns": {
        "password": {
            "transform": {
                "input":  { "type": "text", "function": "encrypt_password" },
                "output": { "type": "text", "function": "mask_password" }
            }
        }
    }
}

以 JSON 形式查询

SELECT to_jsonb(products.*) FROM products;

从 JSON 插入

INSERT INTO people (dob, first_name, last_name)
    (SELECT dob, first_name, last_name
     FROM jsonb_populate_record(null::people,
         '{"first_name": "Jane", "last_name": "Doe", "dob": "1981-12-12"}'));

表格阅读器