Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wCI1q-001q11-09 for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Apr 2026 14:12:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wCI1o-007Fg1-14 for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Apr 2026 14:12:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wCI1o-007Fft-0G for pgsql-bugs@lists.postgresql.org; Mon, 13 Apr 2026 14:12:40 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wCI1h-00000000qfy-2jyy for pgsql-bugs@lists.postgresql.org; Mon, 13 Apr 2026 14:12:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 63DECV1L822927; Mon, 13 Apr 2026 10:12:31 -0400 From: Tom Lane To: ma.sao@msa.hinet.net cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19454: PL/pgSQL mishandling jsonb attribute reference In-reply-to: <19454-98a60db746b6dd22@postgresql.org> References: <19454-98a60db746b6dd22@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sun, 12 Apr 2026 15:45:39 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <822925.1776089551.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 13 Apr 2026 10:12:31 -0400 Message-ID: <822926.1776089551@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > It appears the PL/pgSQL assignment operator :=3D 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 :=3D v_payload || tj->'delta'; -- The problematic line > v_payload :=3D (SELECT v_payload || (tj->'delta')); --This avoids the is= sue. 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-PR= ECEDENCE