Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMtdi-0005Pj-Vi for pgsql-sql@arkaria.postgresql.org; Thu, 18 Mar 2021 14:28:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lMtdh-0005QL-UD for pgsql-sql@arkaria.postgresql.org; Thu, 18 Mar 2021 14:28:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMtdh-0005QE-Ng for pgsql-sql@lists.postgresql.org; Thu, 18 Mar 2021 14:28:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMtdf-00080Z-QF for pgsql-sql@lists.postgresql.org; Thu, 18 Mar 2021 14:28:40 +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 12IESXIm3718236; Thu, 18 Mar 2021 10:28:33 -0400 From: Tom Lane To: Torsten Grust cc: pgsql-sql , Gary Stainburn Subject: Re: select into composite type / return In-reply-to: References: <39dcfab9-4eb2-382b-9186-baf722ca56a0@ringways.co.uk> <3523853.1616002010@sss.pgh.pa.us> <9eb42b06-9cfa-1e4b-e42b-6f64e99675a5@ringways.co.uk> <7af5d693-a6a3-d3d4-050a-0898aad8bd77@ringways.co.uk> Comments: In-reply-to Torsten Grust message dated "Thu, 18 Mar 2021 12:10:06 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3718234.1616077713.1@sss.pgh.pa.us> Date: Thu, 18 Mar 2021 10:28:33 -0400 Message-ID: <3718235.1616077713@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Torsten Grust writes: > Hi Gary, > a shot in the dark but maybe > SELECT id, (do_breakdown(id)).* > FROM ... > already does the job? Beware --- what that actually does is expand into SELECT id, (do_breakdown(id)).f1, (do_breakdown(id)).f2, ... so that the function will be invoked N times if it produces N columns. What you generally want to do is invoke the function as a lateral FROM item: SELECT id, f.* FROM table AS t, LATERAL do_breakdown(t.id) AS f; regards, tom lane