pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add basic JSON_TABLE() functionality
Date: Thu, 04 Apr 2024 11:21:35 +0000
Message-ID: <E1rsL9y-000S60-Pn@gemulon.postgresql.org> (raw)

Add basic JSON_TABLE() functionality

JSON_TABLE() allows JSON data to be converted into a relational view
and thus used, for example, in a FROM clause, like other tabular
data.  Data to show in the view is selected from a source JSON object
using a JSON path expression to get a sequence of JSON objects that's
called a "row pattern", which becomes the source to compute the
SQL/JSON values that populate the view's output columns.  Column
values themselves are computed using JSON path expressions applied to
each of the JSON objects comprising the "row pattern", for which the
SQL/JSON query functions added in 6185c9737cf4 are used.

To implement JSON_TABLE() as a table function, this augments the
TableFunc and TableFuncScanState nodes that are currently used to
support XMLTABLE() with some JSON_TABLE()-specific fields.

Note that the JSON_TABLE() spec includes NESTED COLUMNS and PLAN
clauses, which are required to provide more flexibility to extract
data out of nested JSON objects, but they are not implemented here
to keep this commit of manageable size.

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: Andrew Dunstan <andrew@dunslane.net>
Author: Amit Langote <amitlangote09@gmail.com>
Author: Jian He <jian.universality@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, Álvaro Herrera, Jian He

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
Discussion: https://postgr.es/m/CA+HiwqE4XTdfb1nW=Ojoy_tQSRhYt-q_kb6i5d4xcKyrLC1Nbg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/de3600452b61d1bc3967e9e37e86db8956c8f577

Modified Files
--------------
doc/src/sgml/func.sgml                             | 334 +++++++++++
src/backend/commands/explain.c                     |  21 +-
src/backend/executor/execExpr.c                    |  11 +-
src/backend/executor/execExprInterp.c              |   2 +
src/backend/executor/nodeTableFuncscan.c           |  41 +-
src/backend/nodes/makefuncs.c                      |  53 ++
src/backend/nodes/nodeFuncs.c                      |  36 ++
src/backend/parser/Makefile                        |   1 +
src/backend/parser/gram.y                          | 173 +++++-
src/backend/parser/meson.build                     |   1 +
src/backend/parser/parse_clause.c                  |  14 +-
src/backend/parser/parse_expr.c                    |  53 +-
src/backend/parser/parse_jsontable.c               | 421 ++++++++++++++
src/backend/parser/parse_relation.c                |   6 +-
src/backend/parser/parse_target.c                  |   1 +
src/backend/utils/adt/jsonpath_exec.c              | 372 ++++++++++++
src/backend/utils/adt/ruleutils.c                  | 185 +++++-
src/include/nodes/execnodes.h                      |   2 +
src/include/nodes/makefuncs.h                      |   5 +
src/include/nodes/parsenodes.h                     |  66 +++
src/include/nodes/primnodes.h                      |  56 +-
src/include/parser/kwlist.h                        |   3 +
src/include/parser/parse_clause.h                  |   3 +
src/include/utils/jsonpath.h                       |   3 +
src/interfaces/ecpg/test/ecpg_schedule             |   1 +
.../ecpg/test/expected/sql-sqljson_jsontable.c     | 143 +++++
.../test/expected/sql-sqljson_jsontable.stderr     |  16 +
.../test/expected/sql-sqljson_jsontable.stdout     |   1 +
src/interfaces/ecpg/test/sql/Makefile              |   1 +
src/interfaces/ecpg/test/sql/meson.build           |   1 +
src/interfaces/ecpg/test/sql/sqljson_jsontable.pgc |  29 +
src/test/regress/expected/sqljson_jsontable.out    | 636 +++++++++++++++++++++
src/test/regress/parallel_schedule                 |   2 +-
src/test/regress/sql/sqljson_jsontable.sql         | 290 ++++++++++
src/tools/pgindent/typedefs.list                   |  12 +
35 files changed, 2943 insertions(+), 52 deletions(-)



view thread (13+ messages)  latest in thread

Message-ID: <E1rsL9y-000S60-Pn@gemulon.postgresql.org>
Permalink:  ../E1rsL9y-000S60-Pn@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rsL9y-000S60-Pn@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: amitlan@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Add basic JSON_TABLE() functionality
  In-Reply-To: <E1rsL9y-000S60-Pn@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox