SQL/JSON query functions
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 3 Mar 2022 18:11:14 +0000 (13:11 -0500)
committerAndrew Dunstan <andrew@dunslane.net>
Tue, 29 Mar 2022 20:57:13 +0000 (16:57 -0400)
commit1a36bc9dba8eae90963a586d37b6457b32b2fed4
treeeeb155046082dda9284bd8c298874d802bcc37cb
parent3d067c53b26dfeb95da0d75a65614b4d7b45c317
SQL/JSON query functions

This introduces the SQL/JSON functions for querying JSON data using
jsonpath expressions. The functions are:

JSON_EXISTS()
JSON_QUERY()
JSON_VALUE()

All of these functions only operate on jsonb. The workaround for now is
to cast the argument to jsonb.

JSON_EXISTS() tests if the jsonpath expression applied to the jsonb
value yields any values. JSON_VALUE() must return a single value, and an
error occurs if it tries to return multiple values. JSON_QUERY() must
return a json object or array, and there are various WRAPPER options for
handling scalar or multi-value results. Both these functions have
options for handling EMPTY and ERROR conditions.

Nikita Glukhov

Reviewers have included (in no particular order) Andres Freund, Alexander
Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zihong Yu,
Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby.

Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru
39 files changed:
src/backend/executor/execExpr.c
src/backend/executor/execExprInterp.c
src/backend/jit/llvm/llvmjit_expr.c
src/backend/jit/llvm/llvmjit_types.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/makefuncs.c
src/backend/nodes/nodeFuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/util/clauses.c
src/backend/parser/gram.y
src/backend/parser/parse_collate.c
src/backend/parser/parse_expr.c
src/backend/parser/parse_target.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/jsonb.c
src/backend/utils/adt/jsonfuncs.c
src/backend/utils/adt/jsonpath.c
src/backend/utils/adt/jsonpath_exec.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/misc/queryjumble.c
src/include/executor/execExpr.h
src/include/executor/executor.h
src/include/nodes/makefuncs.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/nodes/primnodes.h
src/include/parser/kwlist.h
src/include/utils/formatting.h
src/include/utils/jsonb.h
src/include/utils/jsonfuncs.h
src/include/utils/jsonpath.h
src/test/regress/expected/json_sqljson.out [new file with mode: 0644]
src/test/regress/expected/jsonb_sqljson.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/sql/json_sqljson.sql [new file with mode: 0644]
src/test/regress/sql/jsonb_sqljson.sql [new file with mode: 0644]