Re: BUG #19693: JSON_VALUE/JSON_QUERY PASSING a toasted text value reads the toast pointer instead of the text - Mailing list pgsql-bugs

From Michael Paquier
Subject Re: BUG #19693: JSON_VALUE/JSON_QUERY PASSING a toasted text value reads the toast pointer instead of the text
Date
Msg-id aq3TflHWHS-407w0@paquier.xyz
Whole thread
In response to BUG #19693: JSON_VALUE/JSON_QUERY PASSING a toasted text value reads the toast pointer instead of the text  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #19693: JSON_VALUE/JSON_QUERY PASSING a toasted text value reads the toast pointer instead of the text
List 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

Attachment

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #19700: PostgreSQL: an SP-GiST index on `inet` makes IPv6 rows invisible
Next
From: Srinath Reddy Sadipiralla
Date:
Subject: Re: BUG #19695: JSON_VALUE ... RETURNING jsonb returns NULL for later evaluation once one evaluation returns NULL