Skip to content

Commit 4684a13

Browse files
author
Nikita Glukhov
committed
Add missing json functions and operators
1 parent 61af37e commit 4684a13

File tree

14 files changed

+624
-34
lines changed

14 files changed

+624
-34
lines changed

src/backend/catalog/system_views.sql

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,14 @@ LANGUAGE INTERNAL
13121312
STRICT IMMUTABLE PARALLEL SAFE
13131313
AS 'make_interval';
13141314

1315+
CREATE OR REPLACE FUNCTION
1316+
json_set(json_in json, path text[] , replacement json,
1317+
create_if_missing boolean DEFAULT true)
1318+
RETURNS json
1319+
LANGUAGE INTERNAL
1320+
STRICT IMMUTABLE PARALLEL SAFE
1321+
AS 'json_set';
1322+
13151323
CREATE OR REPLACE FUNCTION
13161324
jsonb_set(jsonb_in jsonb, path text[] , replacement jsonb,
13171325
create_if_missing boolean DEFAULT true)
@@ -1336,6 +1344,14 @@ LANGUAGE INTERNAL
13361344
STRICT IMMUTABLE PARALLEL SAFE
13371345
AS 'parse_ident';
13381346

1347+
CREATE OR REPLACE FUNCTION
1348+
json_insert(json_in json, path text[] , replacement json,
1349+
insert_after boolean DEFAULT false)
1350+
RETURNS json
1351+
LANGUAGE INTERNAL
1352+
STRICT IMMUTABLE PARALLEL SAFE
1353+
AS 'json_insert';
1354+
13391355
CREATE OR REPLACE FUNCTION
13401356
jsonb_insert(jsonb_in jsonb, path text[] , replacement jsonb,
13411357
insert_after boolean DEFAULT false)
@@ -1424,6 +1440,88 @@ LANGUAGE INTERNAL
14241440
STRICT STABLE PARALLEL SAFE
14251441
AS 'jsonb_path_query_first_tz';
14261442

1443+
1444+
CREATE OR REPLACE FUNCTION
1445+
json_path_exists(target json, path jsonpath, vars json DEFAULT '{}',
1446+
silent boolean DEFAULT false)
1447+
RETURNS boolean
1448+
LANGUAGE INTERNAL
1449+
STRICT IMMUTABLE PARALLEL SAFE
1450+
AS 'json_path_exists';
1451+
1452+
CREATE OR REPLACE FUNCTION
1453+
json_path_match(target json, path jsonpath, vars json DEFAULT '{}',
1454+
silent boolean DEFAULT false)
1455+
RETURNS boolean
1456+
LANGUAGE INTERNAL
1457+
STRICT IMMUTABLE PARALLEL SAFE
1458+
AS 'json_path_match';
1459+
1460+
CREATE OR REPLACE FUNCTION
1461+
json_path_query(target json, path jsonpath, vars json DEFAULT '{}',
1462+
silent boolean DEFAULT false)
1463+
RETURNS SETOF json
1464+
LANGUAGE INTERNAL
1465+
STRICT IMMUTABLE PARALLEL SAFE
1466+
AS 'json_path_query';
1467+
1468+
CREATE OR REPLACE FUNCTION
1469+
json_path_query_array(target json, path jsonpath, vars json DEFAULT '{}',
1470+
silent boolean DEFAULT false)
1471+
RETURNS json
1472+
LANGUAGE INTERNAL
1473+
STRICT IMMUTABLE PARALLEL SAFE
1474+
AS 'json_path_query_array';
1475+
1476+
CREATE OR REPLACE FUNCTION
1477+
json_path_query_first(target json, path jsonpath, vars json DEFAULT '{}',
1478+
silent boolean DEFAULT false)
1479+
RETURNS json
1480+
LANGUAGE INTERNAL
1481+
STRICT IMMUTABLE PARALLEL SAFE
1482+
AS 'json_path_query_first';
1483+
1484+
CREATE OR REPLACE FUNCTION
1485+
json_path_exists_tz(target json, path jsonpath, vars json DEFAULT '{}',
1486+
silent boolean DEFAULT false)
1487+
RETURNS boolean
1488+
LANGUAGE INTERNAL
1489+
STRICT STABLE PARALLEL SAFE
1490+
AS 'json_path_exists_tz';
1491+
1492+
CREATE OR REPLACE FUNCTION
1493+
json_path_match_tz(target json, path jsonpath, vars json DEFAULT '{}',
1494+
silent boolean DEFAULT false)
1495+
RETURNS boolean
1496+
LANGUAGE INTERNAL
1497+
STRICT STABLE PARALLEL SAFE
1498+
AS 'json_path_match_tz';
1499+
1500+
CREATE OR REPLACE FUNCTION
1501+
json_path_query_tz(target json, path jsonpath, vars json DEFAULT '{}',
1502+
silent boolean DEFAULT false)
1503+
RETURNS SETOF json
1504+
LANGUAGE INTERNAL
1505+
STRICT STABLE PARALLEL SAFE
1506+
AS 'json_path_query_tz';
1507+
1508+
CREATE OR REPLACE FUNCTION
1509+
json_path_query_array_tz(target json, path jsonpath, vars json DEFAULT '{}',
1510+
silent boolean DEFAULT false)
1511+
RETURNS json
1512+
LANGUAGE INTERNAL
1513+
STRICT STABLE PARALLEL SAFE
1514+
AS 'json_path_query_array_tz';
1515+
1516+
CREATE OR REPLACE FUNCTION
1517+
json_path_query_first_tz(target json, path jsonpath, vars json DEFAULT '{}',
1518+
silent boolean DEFAULT false)
1519+
RETURNS json
1520+
LANGUAGE INTERNAL
1521+
STRICT STABLE PARALLEL SAFE
1522+
AS 'json_path_query_first_tz';
1523+
1524+
14271525
-- default normalization form is NFC, per SQL standard
14281526
CREATE OR REPLACE FUNCTION
14291527
"normalize"(text, text DEFAULT 'NFC')

src/backend/utils/adt/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ OBJS = \
4545
int8.o \
4646
json.o \
4747
json_generic.o \
48+
json_gin.o \
49+
json_op.o \
4850
jsonb.o \
4951
jsonb_gin.o \
5052
jsonb_op.o \

src/backend/utils/adt/json_gin.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* json_gin.c
3+
*
4+
* Portions Copyright (c) 2016, PostgreSQL Global Development Group
5+
*
6+
* IDENTIFICATION
7+
* src/backend/utils/adt/json_gin.c
8+
*
9+
*/
10+
11+
#define gin_compare_jsonb gin_compare_json
12+
#define gin_extract_jsonb gin_extract_json
13+
#define gin_extract_jsonb_query gin_extract_json_query
14+
#define gin_consistent_jsonb gin_consistent_json
15+
#define gin_triconsistent_jsonb gin_triconsistent_json
16+
#define gin_extract_jsonb_path gin_extract_json_path
17+
#define gin_extract_jsonb_query_path gin_extract_json_query_path
18+
#define gin_consistent_jsonb_path gin_consistent_json_path
19+
#define gin_triconsistent_jsonb_path gin_triconsistent_json_path
20+
21+
#define JsonxContainerOps (&jsontContainerOps)
22+
#define JsonxGetDatum(json) JsontGetDatum(json)
23+
24+
#include "utils/json_generic.h"
25+
26+
#include "jsonb_gin.c"

src/backend/utils/adt/json_op.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* json_op.c
3+
*
4+
* Portions Copyright (c) 2016, PostgreSQL Global Development Group
5+
*
6+
* IDENTIFICATION
7+
* src/backend/utils/adt/json_op.c
8+
*
9+
*/
10+
11+
#define jsonb_exists json_exists
12+
#define jsonb_exists_any json_exists_any
13+
#define jsonb_exists_all json_exists_all
14+
#define jsonb_contains json_contains
15+
#define jsonb_contained json_contained
16+
#define jsonb_ne json_ne
17+
#define jsonb_lt json_lt
18+
#define jsonb_gt json_gt
19+
#define jsonb_le json_le
20+
#define jsonb_ge json_ge
21+
#define jsonb_eq json_eq
22+
#define jsonb_cmp json_cmp
23+
#define jsonb_hash json_hash
24+
#define jsonb_hash_extended json_hash_extended
25+
26+
#define JsonxContainerOps (&jsontContainerOps)
27+
#define JsonxGetDatum(json) JsontGetDatum(json)
28+
29+
#include "utils/json_generic.h"
30+
31+
#include "jsonb_op.c"

0 commit comments

Comments
 (0)