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 1uMXwN-00EpG6-NF for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 20:08:55 +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 1uMXwL-004DxW-P9 for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 20:08:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from <0102019737692b90-b251a7ea-b3c5-4477-afff-5986a149580a-000000@mail.rodonnell.ie>) id 1uMXwL-004Dx5-EP for pgsql-general@lists.postgresql.org; Tue, 03 Jun 2025 20:08:54 +0000 Received: from a7-34.smtp-out.eu-west-1.amazonses.com ([54.240.7.34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from <0102019737692b90-b251a7ea-b3c5-4477-afff-5986a149580a-000000@mail.rodonnell.ie>) id 1uMXwJ-0003e2-1f for pgsql-general@postgresql.org; Tue, 03 Jun 2025 20:08:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=dv7fx26oobputowqxkzhnujragfvk7eg; d=rodonnell.ie; t=1748981328; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=5CRjQUWJbka8MrMvMHtQz6yfe2ZZbrA/Hz9lnqOljIM=; b=UZAR4w//Br3F+uhqHChsBFyZm5Yj5+gdtYbT/MtdIqyEFg5c1P3ZF+XtUVxC6Fd7 YF6LlkRzKf7d/5CA1fFdDxju/se5ufdIugN86Uht8vQvPbdCrmmu8t3nIo2dsbi0AAe yo309kqZyWy1RLo7a+BWWSzOVzR70jNx7mOuPyHKs91XrNqKJOQFAq+CbvjI8mjf+7E 8pe/Qj3E1UVogSJAN4NcC4pFo7mtb4KxdxDeXCyaH9/ieDlFO/2ol9go2kHgIj6Wgpv 1H0dv21K8E/s1dxCfEjGN+R+hCrZjSmV3f4vKhfGDUv7A9JWxUSNYzrN+xAL8ZfgQib gD9HpjvIjg== DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ihchhvubuqgjsxyuhssfvqohv7z3u4hn; d=amazonses.com; t=1748981328; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Feedback-ID; bh=5CRjQUWJbka8MrMvMHtQz6yfe2ZZbrA/Hz9lnqOljIM=; b=iHvcYTFwa4vRL+DXGym2LyN6o7SVluHrNI6zN7jfLEnKEI9hPyxitV/P9fW1wQJ8 NHctKGoKlABKUp4GmUa1y7pwKnXM6hSMcRi5DVye5OcGTBcEBHdKocZJ6e0otrVcHuL hecNsJYu1y2TcBoJxxDYBVgfB6M5ELJweOF0gRPA= Message-ID: <0102019737692b90-b251a7ea-b3c5-4477-afff-5986a149580a-000000@eu-west-1.amazonses.com> Date: Tue, 3 Jun 2025 20:08:48 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Combining scalar and row types in RETURNING To: Adrian Klaver , Tom Lane Cc: 'PostgreSQL' 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> <228703a6-f1bf-4af8-a5d6-4edb5bcaa8cf@aklaver.com> Content-Language: en-GB, de-DE From: Ray O'Donnell In-Reply-To: <228703a6-f1bf-4af8-a5d6-4edb5bcaa8cf@aklaver.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Feedback-ID: ::1.eu-west-1.Bw1eu/7Uepg3xcsiFBL71JJRCh2A2yTFrgBhhiulXmU=:AmazonSES X-SES-Outgoing: 2025.06.03-54.240.7.34 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 03/06/2025 20:01, Adrian Klaver wrote: > On 6/3/25 11:18, Ray O'Donnell wrote: >> On 03/06/2025 17:53, Tom Lane wrote: > >> Thanks a million for the explanation, Tom - that makes sense. I tried >> what you suggested, with mixed results: >> >> (i) Running the MERGE as a stand-alone query, with just RETURNING... >> , worked - I got a scalar and a row as expected. >> >> (ii) Running it in a function (actually a DO block), with m_new >> correctly declared as the table type, failed with the same error as >> before. >> >> (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. > > This: > > ... returning t, merge_action() into m_new, m_action > > does not match this: > > LINE 53:         m, merge_action() into m_new, m_action > > > Is this a copy and paste error or two different invocations of the > function? Whoops, sorry, yes, that's a copy-and-paste error - the target table is aliased as "m" in my original. Ray. -- Raymond O'Donnell // Galway // Ireland ray@rodonnell.ie