]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix deparsing of JSON_ARRAY(subquery) with a FORMAT clause
authorRichard Guo <rguo@postgresql.org>
Mon, 27 Jul 2026 01:21:18 +0000 (10:21 +0900)
committerRichard Guo <rguo@postgresql.org>
Mon, 27 Jul 2026 01:21:18 +0000 (10:21 +0900)
commitf4c850d11afc60a4fc4bc782fc40d7b752bf8d7f
tree4649fc03828f9978d2bfe1cf66e2fec078c336eb
parent87f08dbf3499929f4941f224f52ccd6a20081f00
Fix deparsing of JSON_ARRAY(subquery) with a FORMAT clause

Commit 8d829f5a0 introduced the JSCTOR_JSON_ARRAY_QUERY constructor
type so that ruleutils.c could deparse JSON_ARRAY(subquery) using its
original syntax, storing the transformed subquery in a new orig_query
field.  However, the input FORMAT clause of JSON_ARRAY(subquery FORMAT
...) was not preserved for deparsing.  The format was recorded only in
the executable expression kept in the func field, which ruleutils.c
does not inspect, so it is silently dropped.

This is more than cosmetic, because FORMAT JSON changes the result:
without it a text value is treated as a string to be quoted, while
with it the value is treated as already-formatted JSON.

To fix, record the input FORMAT in a new deparse-only field of
JsonConstructorExpr, alongside orig_query, and emit it in ruleutils.c.

Bump catalog version.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/4C89B193-7D54-4705-9CF9-F0D484B9E099@gmail.com
Backpatch-through: 19
src/backend/parser/parse_expr.c
src/backend/utils/adt/ruleutils.c
src/include/catalog/catversion.h
src/include/nodes/primnodes.h
src/test/regress/expected/sqljson.out
src/test/regress/sql/sqljson.sql