跳转到主要内容

omni_json

JSON toolkit

omnigres : JSON toolkit

Overview

ID Extension Package Version Category License Language
2953 omni_json omnigres 0.1.1 FEAT Apache-2.0 C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----dt- No No No Yes no yes

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.1 19 18 17 16 15 omnigres -
RPM PIGSTY 20260212 19 18 17 16 15 omnigres_$v postgresql$v-contrib, postgresql$v-plpython3, python3-pip
DEB PIGSTY 20260212 19 18 17 16 15 postgresql-$v-omnigres postgresql-plpython3-$v, python3-pip
Linux / PG PG19 PG18 PG17 PG16 PG15
el8.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
el8.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
el9.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
el9.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
el10.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
el10.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
d12.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
d12.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
d13.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
d13.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
u22.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
u22.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
u24.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
u24.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
u26.x86_64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212
u26.aarch64 N/A PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212 PIGSTY 20260212

Source

docs.omnigres.org/omni_json/table_mapping/

omnigres-20260212.tar.gz wheel-0.45.1-py3-none-any.whl

pig build pkg omnigres;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install omnigres;		# install via package name, for the active PG version
pig install omni_json;		# install by extension name, for the current active PG version

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 this extension with:

CREATE EXTENSION omni_json;

Usage

omni_json: JSON toolkit

The omni_json extension provides table-to-JSON mapping with custom transformations when converting rows to JSON.

Define a Table Mapping

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

Column Renaming

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

Nested Keys

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

Column Exclusion

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

Column Transformation

Input (JSON to record) and output (record to JSON) transforms:

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

Querying as JSON

SELECT to_jsonb(products.*) FROM products;

Inserting from 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"}'));

表格阅读器