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.94.2) (envelope-from ) id 1uMXMM-00EceU-1u for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 19:31:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uMXMK-003n9E-3Y for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 19:31:40 +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.94.2) (envelope-from ) id 1uMXMJ-003n8u-P5 for pgsql-general@lists.postgresql.org; Tue, 03 Jun 2025 19:31: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.96) (envelope-from ) id 1uMXMI-0003ND-0g for pgsql-general@postgresql.org; Tue, 03 Jun 2025 19:31: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 553JVYOc877616; Tue, 3 Jun 2025 15:31:36 -0400 From: Tom Lane To: "Ray O'Donnell" cc: "'PostgreSQL'" Subject: Re: Combining scalar and row types in RETURNING In-reply-to: <01020197370480a4-f9b53911-e5a8-4bdb-81e5-de41d5db4d8c-000000@eu-west-1.amazonses.com> References: <01020197369aac89-01a7b7b4-b775-471e-ac8e-de8b28d87008-000000@eu-west-1.amazonses.com> <858949.1748969638@sss.pgh.pa.us> <01020197370480a4-f9b53911-e5a8-4bdb-81e5-de41d5db4d8c-000000@eu-west-1.amazonses.com> Comments: In-reply-to "Ray O'Donnell" message dated "Tue, 03 Jun 2025 18:18:51 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <877614.1748979094.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 03 Jun 2025 15:31:34 -0400 Message-ID: <877615.1748979094@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Ray O'Donnell" writes: > (iii) Running (ii) but with the order of the items in RETURNING reversed - >     ... returning t, merge_action() into m_new, m_action > - gave me a different error: > ERROR:  record variable cannot be part of multiple-item INTO list > LINE 53:         m, merge_action() into m_new, m_action > ...which seems to answer my question definitively. Ah, after looking at the source code in that area, plpgsql allows the INTO target to be either a single composite variable, or one or more non-composite variables; the argument being that otherwise it's too hard to decide which RETURNING items match which INTO items. But I think maybe there is still a solution: declare m_into record; ... returning merge_action() m, t into m_into; ... then fetch m_into.m and m_into.t (the latter will be a composite field). I didn't try this approach though. regards, tom lane