pgsql: Fix PASSING of toasted text values in JSON query functions

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix PASSING of toasted text values in JSON query functions
Date: 2026-09-19 11:16:01
Message-ID: E1x7t33-00000000ONk-0wER@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix PASSING of toasted text values in JSON query functions

The PASSING arguments of JSON_EXISTS(), JSON_QUERY(), JSON_VALUE() and
JSON_TABLE() are evaluated by plain expression steps and given to the
jsonpath executor as-is.

When dealing with a varlena, JsonItemFromDatum() was building a
jbvString directly the contents of a varlena. For a varatt_external
(varatt_external[oid/oid8] on HEAD), this ignored that the contents of
the varlena need to be detoasted, leading to incorrect contents
returned.

Let's detoast the value, like the jsonb and json cases. b0feda79fdf0
has fixed the same issue for subscript values in jsonb.

Note that the results of DatumGetTextPP() are allocated in the memory
context used for the evaluation of the expression, which is reset once
per row.

Oversight in 6185c9737cf4.

Author: Chaitanya Choudhary <chaitanyyachoudhary(at)gmail(dot)com>
Author: Shihao Zhong <zhong950419(at)gmail(dot)com>
Discussion: https://postgr.es/m/19693-2ecd2b52c838b3e5@postgresql.org
Backpatch-through: 17

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/backend/utils/adt/jsonpath_exec.c | 12 +++++++----
src/test/regress/expected/sqljson_queryfuncs.out | 26 ++++++++++++++++++++++++
src/test/regress/sql/sqljson_queryfuncs.sql | 16 +++++++++++++++
3 files changed, 50 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Richard Guo 2026-09-19 12:58:31 pgsql: Fix preprocessing of PHV copies pushed down into subqueries
Previous Message Amit Langote 2026-09-19 09:14:28 Re: pgsql: Invalidate RI fast-path metadata on operator family changes