Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 74362b3

Browse files
author
Nikita Glukhov
committed
Add jsonpath operators @* and @?
1 parent 41ce840 commit 74362b3

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/include/catalog/pg_operator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,5 +1853,9 @@ DATA(insert OID = 3286 ( "-" PGNSP PGUID b f f 3802 23 3802 0 0 3303 - - ));
18531853
DESCR("delete array element");
18541854
DATA(insert OID = 3287 ( "#-" PGNSP PGUID b f f 3802 1009 3802 0 0 jsonb_delete_path - - ));
18551855
DESCR("delete path");
1856+
DATA(insert OID = 6075 ( "@*" PGNSP PGUID b f f 3802 6050 3802 0 0 6055 - - ));
1857+
DESCR("jsonpath items");
1858+
DATA(insert OID = 6076 ( "@?" PGNSP PGUID b f f 3802 6050 16 0 0 6073 contsel contjoinsel ));
1859+
DESCR("jsonpath predicate");
18561860

18571861
#endif /* PG_OPERATOR_H */

src/include/catalog/pg_proc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5483,7 +5483,7 @@ DESCR("I/O");
54835483
DATA(insert OID = 6054 ( _jsonpath_exists PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 16 "3802 6050" _null_ _null_ _null_ _null_ _null_ jsonb_jsonpath_exists2 _null_ _null_ _null_ ));
54845484
DESCR("jsonpath exists test");
54855485
DATA(insert OID = 6055 ( _jsonpath_query PGNSP PGUID 12 1 1000 0 0 f f f f t t i s 2 0 3802 "3802 6050" _null_ _null_ _null_ _null_ _null_ jsonb_jsonpath_query2 _null_ _null_ _null_ ));
5486-
DESCR("jsonpath query");
5486+
DESCR("implementation of @* operator");
54875487
DATA(insert OID = 6056 ( _jsonpath_exists PGNSP PGUID 12 1 0 0 0 f f f f t f i s 3 0 16 "3802 6050 3802" _null_ _null_ _null_ _null_ _null_ jsonb_jsonpath_exists3 _null_ _null_ _null_ ));
54885488
DESCR("jsonpath exists test");
54895489
DATA(insert OID = 6057 ( _jsonpath_query PGNSP PGUID 12 1 1000 0 0 f f f f t t i s 3 0 3802 "3802 6050 3802" _null_ _null_ _null_ _null_ _null_ jsonb_jsonpath_query3 _null_ _null_ _null_ ));
@@ -5493,7 +5493,7 @@ DESCR("jsonpath query, empty on error");
54935493
DATA(insert OID = 6059 ( _jsonpath_query_safe PGNSP PGUID 12 1 1000 0 0 f f f f t t i s 3 0 3802 "3802 6050 3802" _null_ _null_ _null_ _null_ _null_ jsonb_jsonpath_query_safe3 _null_ _null_ _null_ ));
54945494
DESCR("jsonpath query, empty on error");
54955495
DATA(insert OID = 6073 ( _jsonpath_predicate PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 16 "3802 6050" _null_ _null_ _null_ _null_ _null_ jsonb_jsonpath_predicate2 _null_ _null_ _null_ ));
5496-
DESCR("jsonpath predicate test");
5496+
DESCR("implementation of @? operator");
54975497
DATA(insert OID = 6074 ( _jsonpath_predicate PGNSP PGUID 12 1 0 0 0 f f f f t f i s 3 0 16 "3802 6050 3802" _null_ _null_ _null_ _null_ _null_ jsonb_jsonpath_predicate3 _null_ _null_ _null_ ));
54985498
DESCR("jsonpath predicate test");
54995499

src/test/regress/expected/jsonb_jsonpath.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,3 +1554,28 @@ select _jsonpath_query(jsonb
15541554
"Fri Mar 10 02:35:00 2017 PST"
15551555
(2 rows)
15561556

1557+
-- jsonpath operators
1558+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @* '$[*]';
1559+
?column?
1560+
----------
1561+
{"a": 1}
1562+
{"a": 2}
1563+
(2 rows)
1564+
1565+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @* '$[*] ? (@.a > 10)';
1566+
?column?
1567+
----------
1568+
(0 rows)
1569+
1570+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*].a > 1';
1571+
?column?
1572+
----------
1573+
t
1574+
(1 row)
1575+
1576+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*].a > 2';
1577+
?column?
1578+
----------
1579+
f
1580+
(1 row)
1581+

src/test/regress/sql/jsonb_jsonpath.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,11 @@ select _jsonpath_query(jsonb
361361
'["10.03.2017 12:34 +1", "10.03.2017 12:35 +1", "10.03.2017 12:36 +1", "10.03.2017 12:35 +2", "10.03.2017 12:35 -2"]',
362362
'$[*].datetime("dd.mm.yyyy HH24:MI TZH") ? (@ < "10.03.2017 12:35 +1".datetime("dd.mm.yyyy HH24:MI TZH"))'
363363
);
364+
365+
-- jsonpath operators
366+
367+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @* '$[*]';
368+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @* '$[*] ? (@.a > 10)';
369+
370+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*].a > 1';
371+
SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*].a > 2';

0 commit comments

Comments
 (0)