pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19454: PL/pgSQL mishandling jsonb attribute reference
3+ messages / 3 participants
[nested] [flat]
* BUG #19454: PL/pgSQL mishandling jsonb attribute reference
@ 2026-04-12 15:45 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 2 replies; 3+ messages in thread
From: PG Bug reporting form @ 2026-04-12 15:45 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: ma.sao@msa.hinet.net
The following bug has been logged on the website:
Bug reference: 19454
Logged by: CN Liou
Email address: ma.sao@msa.hinet.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 $$;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #19454: PL/pgSQL mishandling jsonb attribute reference
@ 2026-04-13 14:10 David G. Johnston <david.g.johnston@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: David G. Johnston @ 2026-04-13 14:10 UTC (permalink / raw)
To: ma.sao@msa.hinet.net <ma.sao@msa.hinet.net>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
On Sunday, April 12, 2026, PG Bug reporting form <noreply@postgresql.org>
wrote:
> The following bug has been logged on the website:
>
> Bug reference: 19454
> Logged by: CN Liou
> Email address: ma.sao@msa.hinet.net
> PostgreSQL version: 18.3
> Operating system: Linux Debian Bookworm
> Description:
>
> v_payload := v_payload || tj->'delta'; -- The problematic line
> --v_payload := (SELECT v_payload || (tj->'delta')); --This avoids
> the issue.
>
I’m not following. The problematic line above is indeed annoying but it’s
not a bug. Operator precedence is behaving as documented. The second line
(wrapping tj->’delta’ with parentheses) is simply the necessary way to
write many expressions involving the “->”-like json[b] operators.
David J.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #19454: PL/pgSQL mishandling jsonb attribute reference
@ 2026-04-13 14:12 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2026-04-13 14:12 UTC (permalink / raw)
To: ma.sao@msa.hinet.net; +Cc: pgsql-bugs@lists.postgresql.org
PG Bug reporting form <noreply@postgresql.org> writes:
> 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.
Your problem is operator precedence:
> v_payload := v_payload || tj->'delta'; -- The problematic line
> v_payload := (SELECT v_payload || (tj->'delta')); --This avoids the issue.
The second formulation works because of the "extra" parentheses;
that is,
v_payload || tj->'delta'
is parsed as
(v_payload || tj)->'delta'
but what you need is
v_payload || (tj->'delta')
Yeah, this isn't super intuitive, but all our non-SQL-standard
operators have the same precedence [1], so || and -> associate
left-to-right by default.
regards, tom lane
[1] https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-04-13 14:12 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-12 15:45 BUG #19454: PL/pgSQL mishandling jsonb attribute reference PG Bug reporting form <noreply@postgresql.org>
2026-04-13 14:10 ` David G. Johnston <david.g.johnston@gmail.com>
2026-04-13 14:12 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox