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 1uMUto-00DTCX-4F for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 16:54:04 +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 1uMUtl-0028K5-Nv for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 16:54:02 +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 ) id 1uMUtl-0028Jb-Dg for pgsql-general@lists.postgresql.org; Tue, 03 Jun 2025 16:54:02 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uMUtj-00028c-1x for pgsql-general@postgresql.org; Tue, 03 Jun 2025 16:54:00 +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 553GrwCY858950; Tue, 3 Jun 2025 12:53:58 -0400 From: Tom Lane To: "Ray O'Donnell" cc: "'PostgreSQL'" Subject: Re: Combining scalar and row types in RETURNING In-reply-to: <01020197369aac89-01a7b7b4-b775-471e-ac8e-de8b28d87008-000000@eu-west-1.amazonses.com> References: <01020197369aac89-01a7b7b4-b775-471e-ac8e-de8b28d87008-000000@eu-west-1.amazonses.com> Comments: In-reply-to "Ray O'Donnell" message dated "Tue, 03 Jun 2025 16:23:15 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <858948.1748969638.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 03 Jun 2025 12:53:58 -0400 Message-ID: <858949.1748969638@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Ray O'Donnell" writes: > Can you combine scalar and row types in a RETURNING clause? I think so. > declare >     m_action text; >     m_new_data record; > begin >     merge into my_table t >     using ( >         .... >     ) s >     on (t.id = s.id) >     when matched then >         update ..... >     when not matched then >         insert ..... >     returning >         merge_action(), t.* >     into >        m_action, m_new_data; I think the problem here is that "t.*" gets expanded into a list of all of t's columns, just as would happen in a SELECT's output list. Try returning merge_action(), t It might also be necessary to declare the target variable "m_new_data" as being of type my_table rather than generic "record"; not sure about that. regards, tom lane