pgsql: Treat JsonConstructorExpr as non-strict

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Treat JsonConstructorExpr as non-strict
Date: 2025-09-16 09:47:33
Message-ID: E1uySHd-000z6x-0E@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Treat JsonConstructorExpr as non-strict

JsonConstructorExpr can produce non-NULL output with a NULL input, so
it should be treated as a non-strict construct. Failing to do so can
lead to incorrect query behavior.

For example, in the reported case, when pulling up a subquery that is
under an outer join, if the subquery's target list contains a
JsonConstructorExpr that uses subquery variables and it is mistakenly
treated as strict, it will be pulled up without being wrapped in a
PlaceHolderVar. As a result, the expression will be evaluated at the
wrong place and will not be forced to null when the outer join should
do so.

Back-patch to v16 where JsonConstructorExpr was introduced.

Bug: #19046
Reported-by: Runyuan He <runyuan(at)berkeley(dot)edu>
Author: Tender Wang <tndrwang(at)gmail(dot)com>
Co-authored-by: Richard Guo <guofenglinux(at)gmail(dot)com>
Discussion: https://postgr.es/m/19046-765b6602b0a8cfdf@postgresql.org
Backpatch-through: 16

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/62397bb1893ba4f0b5e3a715ba21ee3c6a211d93

Modified Files
--------------
src/backend/optimizer/util/clauses.c | 2 ++
src/test/regress/expected/subselect.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql | 17 +++++++++++++++++
3 files changed, 47 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-09-16 14:10:04 pgsql: Add regression expected-files for older OpenSSL in FIPS mode.
Previous Message Richard Guo 2025-09-16 09:45:54 pgsql: Treat JsonConstructorExpr as non-strict