BUG #19454: PL/pgSQL mishandling jsonb attribute reference

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: ma(dot)sao(at)msa(dot)hinet(dot)net
Subject: BUG #19454: PL/pgSQL mishandling jsonb attribute reference
Date: 2026-04-12 15:45:39
Message-ID: 19454-98a60db746b6dd22@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19454
Logged by: CN Liou
Email address: ma(dot)sao(at)msa(dot)hinet(dot)net
PostgreSQL version: 18.3
Operating system: Linux Debian Bookworm
Description:

It appears the PL/pgSQL assignment operator := fails to maintain the
stability of a jsonb attribute reference (from a function result) during a
self-concatenation operation, whereas a SELECT wrapper forces correct
materialization.

DO $$
DECLARE
v_payload JSONB := '[]'::jsonb;
tj JSONB;
BEGIN
tj := '{"delta": [["1221", "1221", "TWD", 577.82, {"tags":
[]}]]}'::jsonb;
RAISE NOTICE 'Before: %, Delta is Null: %', (v_payload IS NULL),
(tj->'delta' IS NULL);
v_payload := v_payload || tj->'delta'; -- The problematic line
--v_payload := (SELECT v_payload || (tj->'delta')); --This avoids
the issue.
RAISE NOTICE 'After: %', (v_payload IS NULL);
END $$;

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-04-13 12:48:35 BUG #19455: ALTER TABLE RENAME will rename a sequence
Previous Message Etsuro Fujita 2026-04-12 07:05:25 Re: Re: Re: FDW connection drops with "Connection timed out" during async append query due to TCP receive buffer filling up