Skip to content

Commit 7ac0193

Browse files
author
Nikita Glukhov
committed
Add missing json functions and operators
1 parent 9073c78 commit 7ac0193

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
@@ -1315,6 +1315,14 @@ LANGUAGE INTERNAL
13151315
STRICT IMMUTABLE PARALLEL SAFE
13161316
AS 'make_interval';
13171317

1318+
CREATE OR REPLACE FUNCTION
1319+
json_set(json_in json, path text[] , replacement json,
1320+
create_if_missing boolean DEFAULT true)
1321+
RETURNS json
1322+
LANGUAGE INTERNAL
1323+
STRICT IMMUTABLE PARALLEL SAFE
1324+
AS 'json_set';
1325+
13181326
CREATE OR REPLACE FUNCTION
13191327
jsonb_set(jsonb_in jsonb, path text[] , replacement jsonb,
13201328
create_if_missing boolean DEFAULT true)
@@ -1339,6 +1347,14 @@ LANGUAGE INTERNAL
13391347
STRICT IMMUTABLE PARALLEL SAFE
13401348
AS 'parse_ident';
13411349

1350+
CREATE OR REPLACE FUNCTION
1351+
json_insert(json_in json, path text[] , replacement json,
1352+
insert_after boolean DEFAULT false)
1353+
RETURNS json
1354+
LANGUAGE INTERNAL
1355+
STRICT IMMUTABLE PARALLEL SAFE
1356+
AS 'json_insert';
1357+
13421358
CREATE OR REPLACE FUNCTION
13431359
jsonb_insert(jsonb_in jsonb, path text[] , replacement jsonb,
13441360
insert_after boolean DEFAULT false)
@@ -1427,6 +1443,88 @@ LANGUAGE INTERNAL
14271443
STRICT STABLE PARALLEL SAFE
14281444
AS 'jsonb_path_query_first_tz';
14291445

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