Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3nbS-0002sg-Lb for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 20:34:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i3nbR-0003Hp-I9 for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 20:34:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3nbR-0003Hi-91 for pgsql-general@lists.postgresql.org; Fri, 30 Aug 2019 20:34:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3nbK-00086O-Mv for pgsql-general@lists.postgresql.org; Fri, 30 Aug 2019 20:34:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7UKYREJ009271; Fri, 30 Aug 2019 16:34:27 -0400 From: Tom Lane To: Rob Sargent cc: Guyren Howe , stan , "pgsql-general@lists.postgresql.org" Subject: Re: Returning a table from a function, that requires multiple selects? In-reply-to: <4E2CEFF7-7FBF-43B2-A407-5B7A67BCA4AB@gmail.com> References: <20190830200315.GA28175@panix.com> <4E2CEFF7-7FBF-43B2-A407-5B7A67BCA4AB@gmail.com> Comments: In-reply-to Rob Sargent message dated "Fri, 30 Aug 2019 14:23:32 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <9269.1567197267.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 30 Aug 2019 16:34:27 -0400 Message-ID: <9270.1567197267@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rob Sargent writes: >> On Aug 30, 2019, at 2:09 PM, Guyren Howe wrote: >> = >> On Aug 30, 2019, at 13:03 , stan > wrote: >>> Is it possible for a function to return a table with results from mult= iple >>> queries? >> You could just return a tuple VALUES(a, b). Or you could define a type = to return if you want to get fancy. > Here I you might want VALUE(array[=E2=80=98heading1=E2=80=99,a], array[=E2= =80=98heading2',b]) unless you=E2=80=99re certain you know which date is w= hich. Yeah, that would be a good reason to return a declared composite type. Something like CREATE TYPE two_dates AS (start date, stop date); CREATE FUNCTION f(...) RETURNS two_dates AS ...; SELECT * FROM f(...); regards, tom lane