SQL/JSON: add standard JSON constructor functions

Alvaro Herrera <alvherre@alvh.no-ip.org>

Commit: 7081ac46ace8c459966174400b53418683c9fe5c
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: 2023-03-29T10:11:36Z
Releases: 16.0
SQL/JSON: add standard JSON constructor functions

This commit introduces the SQL/JSON standard-conforming constructors for
JSON types:

JSON_ARRAY()
JSON_ARRAYAGG()
JSON_OBJECT()
JSON_OBJECTAGG()

Most of the functionality was already present in PostgreSQL-specific
functions, but these include some new functionality such as the ability
to skip or include NULL values, and to allow duplicate keys or throw
error when they are found, as well as the standard specified syntax to
specify output type and format.

Author: Nikita Glukhov <n.gluhov@postgrespro.ru>
Author: Teodor Sigaev <teodor@sigaev.ru>
Author: Oleg Bartunov <obartunov@gmail.com>
Author: Alexander Korotkov <aekorotkov@gmail.com>
Author: Amit Langote <amitlangote09@gmail.com>

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/CAF4Au4w2x-5LTnN_bxky-mq4=WOqsGsxSpENCzHRAzSnEd8+WQ@mail.gmail.com
Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru
Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de
Discussion: https://postgr.es/m/abd9b83b-aa66-f230-3d6d-734817f0995d%40postgresql.org

Files

PathChange+/−
doc/src/sgml/func.sgml modified +283 −3
src/backend/executor/execExpr.c modified +91 −0
src/backend/executor/execExprInterp.c modified +50 −0
src/backend/jit/llvm/llvmjit_expr.c modified +6 −0
src/backend/jit/llvm/llvmjit_types.c modified +1 −0
src/backend/nodes/makefuncs.c modified +69 −0
src/backend/nodes/nodeFuncs.c modified +221 −0
src/backend/optimizer/util/clauses.c modified +55 −0
src/backend/parser/gram.y modified +251 −6
src/backend/parser/parse_expr.c modified +770 −0
src/backend/parser/parser.c modified +26 −0
src/backend/parser/parse_target.c modified +18 −0
src/backend/utils/adt/jsonb.c modified +195 −41
src/backend/utils/adt/jsonb_util.c modified +41 −15
src/backend/utils/adt/json.c modified +386 −48
src/backend/utils/adt/ruleutils.c modified +260 −15
src/include/catalog/catversion.h modified +1 −1
src/include/catalog/pg_aggregate.dat modified +22 −0
src/include/catalog/pg_proc.dat modified +74 −0
src/include/executor/execExpr.h modified +26 −0
src/include/nodes/makefuncs.h modified +6 −0
src/include/nodes/parsenodes.h modified +107 −0
src/include/nodes/primnodes.h modified +85 −0
src/include/parser/kwlist.h modified +8 −0
src/include/utils/jsonb.h modified +9 −0
src/include/utils/json.h modified +6 −0
src/interfaces/ecpg/preproc/parse.pl modified +2 −0
src/interfaces/ecpg/preproc/parser.c modified +22 −0
src/interfaces/ecpg/test/ecpg_schedule modified +1 −0
src/interfaces/ecpg/test/expected/sql-sqljson.c added +203 −0
src/interfaces/ecpg/test/expected/sql-sqljson.stderr added +69 −0
src/interfaces/ecpg/test/expected/sql-sqljson.stdout added +6 −0
src/interfaces/ecpg/test/sql/Makefile modified +1 −0
src/interfaces/ecpg/test/sql/meson.build modified +1 −0
src/interfaces/ecpg/test/sql/sqljson.pgc added +44 −0
src/test/regress/expected/json.out modified +4 −7
src/test/regress/expected/opr_sanity.out modified +4 −2
src/test/regress/expected/sqljson.out added +756 −0
src/test/regress/parallel_schedule modified +1 −1
src/test/regress/sql/opr_sanity.sql modified +4 −2
src/test/regress/sql/sqljson.sql added +284 −0
src/tools/pgindent/typedefs.list modified +1 −0

Documentation touched

Discussion