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