Re: BUG #19693: JSON_VALUE/JSON_QUERY PASSING a toasted text value reads the toast pointer instead of the text

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: chaitanyyachoudhary(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19693: JSON_VALUE/JSON_QUERY PASSING a toasted text value reads the toast pointer instead of the text
Date: 2026-09-19 00:12:46
Message-ID: aq3TflHWHS-407w0@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Sep 18, 2026 at 02:39:08AM +0000, PG Bug reporting form wrote:
> The datum is never detoasted, so for an out-of-line value the macros read
> the toast pointer's own bytes. The value comes from the PASSING argument
> via GetJsonPathVar() -> JsonItemFromDatum(var->value, ...) and nothing on
> that path detoasts it either. The other varlena cases in this function
> (JSONB, and the datetime types through their output paths) go through code
> that detoasts.
>
> Fix: detoast the datum in that case, for example
>
> text *txt = DatumGetTextPP(val);
> res->val.string.val = VARDATA_ANY(txt);
> res->val.string.len = VARSIZE_ANY_EXHDR(txt);
>
> The same code is present on REL_18_STABLE and master as of 2026-09-17.

At quick glance, your take seems right and that looks like an
oversight. Would you like to write a patch?
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Srinath Reddy Sadipiralla 2026-09-19 00:58:37 Re: BUG #19695: JSON_VALUE ... RETURNING jsonb returns NULL for later evaluation once one evaluation returns NULL
Previous Message PG Bug reporting form 2026-09-18 23:36:04 BUG #19700: PostgreSQL: an SP-GiST index on `inet` makes IPv6 rows invisible