pgjq

pgjq

pgjq : Use jq in Postgres

Overview

ID Extension Package Version Category License Language
4150
pgjq
pgjq
0.1.0
UTIL
MIT
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-dtr
No
Yes
No
Yes
yes
yes
Relationships
See Also
pgjwt
pg_protobuf
jsquery
sparql
gzip
bzip
zstd
http

build with jq-devel

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.1.0
18
17
16
15
14
pgjq -
RPM
PIGSTY
0.1.0
18
17
16
15
14
pgjq_$v -
DEB
PIGSTY
0.1.0
18
17
16
15
14
postgresql-$v-pgjq -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el8.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el9.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
el10.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d12.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
d13.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u22.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.x86_64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
u24.aarch64
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
PIGSTY 0.1.0
Package Version OS ORG SIZE File URL
pgjq_18 0.1.0 el8.x86_64 pigsty 17.8 KiB pgjq_18-0.1.0-1PIGSTY.el8.x86_64.rpm
pgjq_18 0.1.0 el8.aarch64 pigsty 17.9 KiB pgjq_18-0.1.0-1PIGSTY.el8.aarch64.rpm
pgjq_18 0.1.0 el9.x86_64 pigsty 18.2 KiB pgjq_18-0.1.0-1PIGSTY.el9.x86_64.rpm
pgjq_18 0.1.0 el9.aarch64 pigsty 18.0 KiB pgjq_18-0.1.0-1PIGSTY.el9.aarch64.rpm
pgjq_18 0.1.0 el10.x86_64 pigsty 18.1 KiB pgjq_18-0.1.0-1PIGSTY.el10.x86_64.rpm
pgjq_18 0.1.0 el10.aarch64 pigsty 18.1 KiB pgjq_18-0.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pgjq 0.1.0 d12.x86_64 pigsty 18.5 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pgjq 0.1.0 d12.aarch64 pigsty 18.1 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pgjq 0.1.0 d13.x86_64 pigsty 18.5 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pgjq 0.1.0 d13.aarch64 pigsty 18.1 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pgjq 0.1.0 u22.x86_64 pigsty 19.1 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pgjq 0.1.0 u22.aarch64 pigsty 18.9 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pgjq 0.1.0 u24.x86_64 pigsty 19.5 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~noble_amd64.deb
postgresql-18-pgjq 0.1.0 u24.aarch64 pigsty 18.9 KiB postgresql-18-pgjq_0.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pgjq_17 0.1.0 el8.x86_64 pigsty 17.9 KiB pgjq_17-0.1.0-1PIGSTY.el8.x86_64.rpm
pgjq_17 0.1.0 el8.aarch64 pigsty 17.9 KiB pgjq_17-0.1.0-1PIGSTY.el8.aarch64.rpm
pgjq_17 0.1.0 el9.x86_64 pigsty 18.2 KiB pgjq_17-0.1.0-1PIGSTY.el9.x86_64.rpm
pgjq_17 0.1.0 el9.aarch64 pigsty 18.0 KiB pgjq_17-0.1.0-1PIGSTY.el9.aarch64.rpm
pgjq_17 0.1.0 el10.x86_64 pigsty 18.1 KiB pgjq_17-0.1.0-1PIGSTY.el10.x86_64.rpm
pgjq_17 0.1.0 el10.aarch64 pigsty 18.1 KiB pgjq_17-0.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-pgjq 0.1.0 d12.x86_64 pigsty 18.5 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-pgjq 0.1.0 d12.aarch64 pigsty 18.1 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-pgjq 0.1.0 d13.x86_64 pigsty 18.5 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~trixie_amd64.deb
postgresql-17-pgjq 0.1.0 d13.aarch64 pigsty 18.1 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~trixie_arm64.deb
postgresql-17-pgjq 0.1.0 u22.x86_64 pigsty 20.1 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~jammy_amd64.deb
postgresql-17-pgjq 0.1.0 u22.aarch64 pigsty 19.8 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~jammy_arm64.deb
postgresql-17-pgjq 0.1.0 u24.x86_64 pigsty 19.5 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~noble_amd64.deb
postgresql-17-pgjq 0.1.0 u24.aarch64 pigsty 18.8 KiB postgresql-17-pgjq_0.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pgjq_16 0.1.0 el8.x86_64 pigsty 17.8 KiB pgjq_16-0.1.0-1PIGSTY.el8.x86_64.rpm
pgjq_16 0.1.0 el8.aarch64 pigsty 17.9 KiB pgjq_16-0.1.0-1PIGSTY.el8.aarch64.rpm
pgjq_16 0.1.0 el9.x86_64 pigsty 18.2 KiB pgjq_16-0.1.0-1PIGSTY.el9.x86_64.rpm
pgjq_16 0.1.0 el9.aarch64 pigsty 18.0 KiB pgjq_16-0.1.0-1PIGSTY.el9.aarch64.rpm
pgjq_16 0.1.0 el10.x86_64 pigsty 18.1 KiB pgjq_16-0.1.0-1PIGSTY.el10.x86_64.rpm
pgjq_16 0.1.0 el10.aarch64 pigsty 18.1 KiB pgjq_16-0.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-16-pgjq 0.1.0 d12.x86_64 pigsty 18.5 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-16-pgjq 0.1.0 d12.aarch64 pigsty 18.1 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-16-pgjq 0.1.0 d13.x86_64 pigsty 18.5 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~trixie_amd64.deb
postgresql-16-pgjq 0.1.0 d13.aarch64 pigsty 18.1 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~trixie_arm64.deb
postgresql-16-pgjq 0.1.0 u22.x86_64 pigsty 20.1 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~jammy_amd64.deb
postgresql-16-pgjq 0.1.0 u22.aarch64 pigsty 19.8 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~jammy_arm64.deb
postgresql-16-pgjq 0.1.0 u24.x86_64 pigsty 19.5 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~noble_amd64.deb
postgresql-16-pgjq 0.1.0 u24.aarch64 pigsty 18.9 KiB postgresql-16-pgjq_0.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pgjq_15 0.1.0 el8.x86_64 pigsty 17.9 KiB pgjq_15-0.1.0-1PIGSTY.el8.x86_64.rpm
pgjq_15 0.1.0 el8.aarch64 pigsty 17.9 KiB pgjq_15-0.1.0-1PIGSTY.el8.aarch64.rpm
pgjq_15 0.1.0 el9.x86_64 pigsty 18.2 KiB pgjq_15-0.1.0-1PIGSTY.el9.x86_64.rpm
pgjq_15 0.1.0 el9.aarch64 pigsty 18.0 KiB pgjq_15-0.1.0-1PIGSTY.el9.aarch64.rpm
pgjq_15 0.1.0 el10.x86_64 pigsty 18.1 KiB pgjq_15-0.1.0-1PIGSTY.el10.x86_64.rpm
pgjq_15 0.1.0 el10.aarch64 pigsty 18.1 KiB pgjq_15-0.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-15-pgjq 0.1.0 d12.x86_64 pigsty 18.5 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-15-pgjq 0.1.0 d12.aarch64 pigsty 18.1 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-15-pgjq 0.1.0 d13.x86_64 pigsty 18.5 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~trixie_amd64.deb
postgresql-15-pgjq 0.1.0 d13.aarch64 pigsty 18.1 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~trixie_arm64.deb
postgresql-15-pgjq 0.1.0 u22.x86_64 pigsty 20.1 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~jammy_amd64.deb
postgresql-15-pgjq 0.1.0 u22.aarch64 pigsty 19.8 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~jammy_arm64.deb
postgresql-15-pgjq 0.1.0 u24.x86_64 pigsty 19.5 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~noble_amd64.deb
postgresql-15-pgjq 0.1.0 u24.aarch64 pigsty 18.9 KiB postgresql-15-pgjq_0.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pgjq_14 0.1.0 el8.x86_64 pigsty 17.8 KiB pgjq_14-0.1.0-1PIGSTY.el8.x86_64.rpm
pgjq_14 0.1.0 el8.aarch64 pigsty 17.9 KiB pgjq_14-0.1.0-1PIGSTY.el8.aarch64.rpm
pgjq_14 0.1.0 el9.x86_64 pigsty 18.2 KiB pgjq_14-0.1.0-1PIGSTY.el9.x86_64.rpm
pgjq_14 0.1.0 el9.aarch64 pigsty 18.0 KiB pgjq_14-0.1.0-1PIGSTY.el9.aarch64.rpm
pgjq_14 0.1.0 el10.x86_64 pigsty 18.0 KiB pgjq_14-0.1.0-1PIGSTY.el10.x86_64.rpm
pgjq_14 0.1.0 el10.aarch64 pigsty 18.1 KiB pgjq_14-0.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-14-pgjq 0.1.0 d12.x86_64 pigsty 18.5 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-14-pgjq 0.1.0 d12.aarch64 pigsty 18.0 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-14-pgjq 0.1.0 d13.x86_64 pigsty 18.4 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~trixie_amd64.deb
postgresql-14-pgjq 0.1.0 d13.aarch64 pigsty 18.0 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~trixie_arm64.deb
postgresql-14-pgjq 0.1.0 u22.x86_64 pigsty 20.0 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~jammy_amd64.deb
postgresql-14-pgjq 0.1.0 u22.aarch64 pigsty 19.8 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~jammy_arm64.deb
postgresql-14-pgjq 0.1.0 u24.x86_64 pigsty 19.5 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~noble_amd64.deb
postgresql-14-pgjq 0.1.0 u24.aarch64 pigsty 18.8 KiB postgresql-14-pgjq_0.1.0-1PIGSTY~noble_arm64.deb

Source

pig build pkg pgjq;		# 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 pgjq;		# install via package name, for the active PG version

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

Create this extension with:

CREATE EXTENSION pgjq;

Usage

pgjq: Use jq JSON processing language in PostgreSQL

Provides a jqprog data type for jq programs and a jq() function to execute them on jsonb objects.

Basic Filtering

SELECT jq('[{"bar": "baz", "balance": 7.77}]'::jsonb, '.[0].bar');
-- "baz"

Using the @@ Operator

SELECT '[{"bar": "baz"}]' @@ '.[0].bar'::jqprog;
-- "baz"

Complex Programs

SELECT jq('[true,false,[5,true,[true,[false]],false]]',
          '(..|select(type=="boolean")) |= if . then 1 else 0 end');
-- [1, 0, [5, 1, [1, [0]], 0]]

SELECT jq('[1,5,3,0,7]', '(.[] | select(. >= 2)) |= empty');
-- [1, 0]

Passing Arguments

Pass dynamic arguments as a jsonb object, referenced as $var:

SELECT jq(
    '{"jobs": [{"id": 9, "ok": true}, {"id": 100, "ok": false}]}'::jsonb,
    '.jobs[] | select(.ok == $ok and .id == 100) | .',
    '{"ok": false}'
);

Chaining with jsonpath

SELECT jq('[{"cust":"baz","active":true,"trans":{"balance":100}}]',
          '(.[] | select(.active == true))') - '{trans}' @> '{"cust": "baz"}';
-- t

Working with Files

SELECT jq(pg_read_file('/path/to/data.json'), '.[]');
Last updated on