agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix PASSING of toasted text values in JSON query functions
Date: Sat, 19 Sep 2026 11:16:01 +0000
Message-ID: <E1x7t33-00000000ONi-0rtL@gemulon.postgresql.org> (raw)

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@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/19693-2ecd2b52c838b3e5@postgresql.org
Backpatch-through: 17

Branch
------
master

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

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(-)



view thread (4+ messages)  latest in thread

Message-ID: <E1x7t33-00000000ONi-0rtL@gemulon.postgresql.org>
Permalink:  ../E1x7t33-00000000ONi-0rtL@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x7t33-00000000ONi-0rtL@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: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix PASSING of toasted text values in JSON query functions
  In-Reply-To: <E1x7t33-00000000ONi-0rtL@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox