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
|
Source
pig build pkg pgjq; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
CREATE EXTENSION pgjq;Usage
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"}';
-- tWorking with Files
SELECT jq(pg_read_file('/path/to/data.json'), '.[]');Last updated on