public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Re: BUG #19454: PL/pgSQL mishandling jsonb attribute reference
Date: Mon, 13 Apr 2026 10:12:31 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

PG Bug reporting form <[email protected]> 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






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: BUG #19454: PL/pgSQL mishandling jsonb attribute reference
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox