pgsql: SQL/JSON query functions

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: SQL/JSON query functions
Date: 2022-03-29 20:57:37
Message-ID: E1nZIuG-001xDg-KJ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1a36bc9dba8eae90963a586d37b6457b32b2fed4

Modified Files
--------------
src/backend/executor/execExpr.c | 206 ++++--
src/backend/executor/execExprInterp.c | 543 ++++++++++++++
src/backend/jit/llvm/llvmjit_expr.c | 6 +
src/backend/jit/llvm/llvmjit_types.c | 1 +
src/backend/nodes/copyfuncs.c | 150 ++++
src/backend/nodes/equalfuncs.c | 127 ++++
src/backend/nodes/makefuncs.c | 15 +
src/backend/nodes/nodeFuncs.c | 186 ++++-
src/backend/nodes/outfuncs.c | 70 ++
src/backend/nodes/readfuncs.c | 86 +++
src/backend/optimizer/path/costsize.c | 3 +-
src/backend/optimizer/util/clauses.c | 32 +
src/backend/parser/gram.y | 333 ++++++++-
src/backend/parser/parse_collate.c | 4 +
src/backend/parser/parse_expr.c | 490 ++++++++++++-
src/backend/parser/parse_target.c | 15 +
src/backend/utils/adt/formatting.c | 45 +-
src/backend/utils/adt/jsonb.c | 62 ++
src/backend/utils/adt/jsonfuncs.c | 50 +-
src/backend/utils/adt/jsonpath.c | 257 +++++++
src/backend/utils/adt/jsonpath_exec.c | 350 +++++++--
src/backend/utils/adt/ruleutils.c | 135 ++++
src/backend/utils/misc/queryjumble.c | 21 +
src/include/executor/execExpr.h | 54 ++
src/include/executor/executor.h | 2 +
src/include/nodes/makefuncs.h | 1 +
src/include/nodes/nodes.h | 7 +
src/include/nodes/parsenodes.h | 59 ++
src/include/nodes/primnodes.h | 109 +++
src/include/parser/kwlist.h | 11 +
src/include/utils/formatting.h | 4 +
src/include/utils/jsonb.h | 3 +
src/include/utils/jsonfuncs.h | 4 +
src/include/utils/jsonpath.h | 33 +
src/test/regress/expected/json_sqljson.out | 15 +
src/test/regress/expected/jsonb_sqljson.out | 1018 +++++++++++++++++++++++++++
src/test/regress/parallel_schedule | 2 +-
src/test/regress/sql/json_sqljson.sql | 11 +
src/test/regress/sql/jsonb_sqljson.sql | 317 +++++++++
39 files changed, 4716 insertions(+), 121 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2022-03-29 21:01:52 pgsql: Make PostgreSQL::Test::Cluster::run_log() return a useful value.
Previous Message Thomas Munro 2022-03-29 20:35:31 Re: pgsql: Add 'basebackup_to_shell' contrib module.