Re: SQL/JSON: JSON_TRANSFORM (SQL standard, subclause 6.44)

From: Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: SQL/JSON: JSON_TRANSFORM (SQL standard, subclause 6.44)
Date: 2026-12-06 18:27:43
Message-ID: CAFC+b6pD4OU5XxxOby4SwvP7fRQr_hr5LjLpdGtZtFi7gV43sQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Attached is v5, rebased on master. Changes since v4:

1. Squashed the five v4 patches into two: 0001 adds JSON_TRANSFORM, and
0002 adds the "= PATH <jsonpath>" source.

2. PASSING now has an effect: its variables are passed to the PATH
source, so PATH '$.a + $x' PASSING 10 AS x works.

3. Errors now use the SQLSTATEs from SQL:2023 6.44, added to
errcodes.txt: 22050 (target already exists), 22051 (null in
replacement value not allowed) and 22052 (target does not exist).
A RENAME onto an existing key raises 22037 with its own message, and
a PATH source that returns more than one item gets a
JSON_TRANSFORM-specific message.

4. Invalid target paths are rejected when an index, view or generated
column is defined. Before, only the executor checked the path, so
CREATE INDEX on an empty table accepted e.g. '$[0]' and every later
INSERT failed. A literal path is now checked during parse analysis,
and a path that only becomes a constant during planning (such as
'$[0]'::text) is checked in eval_const_expressions(). The executor
still checks a non-constant path.

5. Deparse omits clauses equal to their default, as JSON_QUERY does.
It also fixes two cases where pg_get_viewdef() output could not be
parsed back, which would break pg_dump and pg_upgrade: a non-constant
value followed by IGNORE ON ... is now parenthesized, and the RENAME
name is printed as a plain literal.

6. Added the regression test sqljson_transform. It covers the four
actions, behavior clauses, lax/strict mode, wildcards, PASSING, the
SQLSTATEs, a deparse round trip, and index cases (mutability,
invalid paths on an empty table, index matching). A view and indexes
are left in place for the pg_upgrade test. The full suite also passes
with jit_above_cost=0 on an LLVM build.

Patches 0001 and 0002 are attached.

>

--
Thanks :)
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/
"Rebuild it…Just the way it was…Brick for brick"

Attachment Content-Type Size
v5-0001-SQL-JSON-Add-JSON_TRANSFORM.patch application/octet-stream 69.0 KB
v5-0002-SQL-JSON-support-PATH-jsonpath-source-in-JSON_TRA.patch application/octet-stream 72.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Dean Rasheed 2026-12-06 17:01:36 Regression tests that test JIT