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 1qlCVa-001iLh-I6 for pgsql-general@arkaria.postgresql.org; Tue, 26 Sep 2023 18:10:07 +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 1qlCVY-00E3sO-Mt for pgsql-general@arkaria.postgresql.org; Tue, 26 Sep 2023 18:10:04 +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 1qlCVW-00E3rw-TA for pgsql-general@lists.postgresql.org; Tue, 26 Sep 2023 18:10:04 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlCVQ-007jDI-MF for pgsql-general@lists.postgresql.org; Tue, 26 Sep 2023 18:10:02 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 80BA95C2630; Tue, 26 Sep 2023 14:09:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 26 Sep 2023 14:09:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1695751794; x=1695838194; bh=Oh KHsL28J+ACMN819T7wC1lfme6BzosDTFlsroXzCIk=; b=hkx0O84FnyoiTp3a6q +88UMNcTkNJlkbhhN+c3w10AJwW5SI3VqCNvFuEJ5pTekiXxh8FK402+LqocaGNC hPGZuxoe+UllAsFA+VNllBJ+72NoT9BkU/j+scITU4fYLImKBRFZxMOdQIh2xRRt OcHT5SzzXkwmWC1lChFdbMfAXObkBDNG6xYYtxNUMKe2VHInAubCHG4RiSIOG2IR FFFmclVeahyU6vDmnKPpmEk6hdZl6dnb3w8ibGQ70FF6+Orb6OwJrTueVrEfb6Lo uP86TGtAbwy+Hiv1YhBs7K/QKIgLqoAEytIXfPsaDwe/XrPFnxE9PerQmv4WUvII H7vw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1695751794; x=1695838194; bh=OhKHsL28J+ACM N819T7wC1lfme6BzosDTFlsroXzCIk=; b=GSeJrn/fYkpaSV+xs3os9NrMVEOWC mpxf2Lh8+VYWHnGYmUH13woWRB0mEpwEPhIsqHUQt56irY+/mdaT6njHRehxXmc2 zvntv1mm519tO1T8W4/HJSvDSrJ7rz8K1sXW5IFYKSXP8XZpYRI5iS7O0Ms1GjvK /ZX2vbDnSSkt/zYidhFrPY3L1+zy1w/iC5OZcdxr4uHvfXKEXt4JT1QKAceo3mbd fRfxW1N24cJIdtcqVJu3+pr+Oz3ER4MgUY6D7vgbnx669VodkWY2CESY3SL30lYo 6pCuATcrE08wFRI/BK0EWZzrmH8Z+59iZPpi6vTSPKm07RlW1nTlfmWxg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvjedrtddtgdeludcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderre dtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepjefgtdeuudefvd ekgeeljeevheeuleejudevgeeludfgkeduiedukeelledtveelnecuffhomhgrihhnpehp ohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Sep 2023 14:09:53 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------ylxkTESWuquoXjNHHgo6GjsI" Message-ID: Date: Tue, 26 Sep 2023 11:09:52 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Ad hoc SETOF type definition? To: Ron , pgsql-general@lists.postgresql.org References: <9707e21e-eed3-3c06-821e-e935eab4c098@gmail.com> <432138.1695750386@sss.pgh.pa.us> <73c7a357-62fe-3274-7f27-7ef9adc3b9b5@gmail.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: <73c7a357-62fe-3274-7f27-7ef9adc3b9b5@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------ylxkTESWuquoXjNHHgo6GjsI Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 9/26/23 11:03 AM, Ron wrote: > On 9/26/23 12:46, Tom Lane wrote: >> Ron writes: >>> Is there a way to define the SETOF record on the fly, like you do with >>> RETURNS TABLE (f1 type1, f2 type2)? >> Doesn't RETURNS TABLE meet the need already? > > That rationale means that RETURN SETOF is not needed, and can be > removed from Pg, since "RETURNS TABLE meet the need already". > > But of course there /are/ times when RETURN SETOF /is/ useful. > > So... can ad hoc SETOF definitions be created in the function > definition, or is CREATE TYPE the only way to do it? That is what RETURNS TABLE does: https://www.postgresql.org/docs/current/sql-createfunction.html "/|column_name|/ The name of an output column in the |RETURNS TABLE| syntax. This is effectively another way of declaring a named |OUT| parameter, except that |RETURNS TABLE| also implies |RETURNS SETOF|. " > > -- > Born in Arizona, moved to Babylonia. --------------ylxkTESWuquoXjNHHgo6GjsI Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit


On 9/26/23 11:03 AM, Ron wrote:
On 9/26/23 12:46, Tom Lane wrote:
Ron <ronljohnsonjr@gmail.com> writes:
Is there a way to define the SETOF record on the fly, like you do with 
RETURNS TABLE (f1 type1, f2 type2)?
Doesn't RETURNS TABLE meet the need already?

That rationale means that RETURN SETOF is not needed, and can be removed from Pg, since "RETURNS TABLE meet the need already".

But of course there are times when RETURN SETOF is useful.

So... can ad hoc SETOF definitions be created in the function definition, or is CREATE TYPE the only way to do it?


That is what RETURNS TABLE does:

https://www.postgresql.org/docs/current/sql-createfunction.html

"column_name

The name of an output column in the RETURNS TABLE syntax. This is effectively another way of declaring a named OUT parameter, except that RETURNS TABLE also implies RETURNS SETOF.

"

--
Born in Arizona, moved to Babylonia.
--------------ylxkTESWuquoXjNHHgo6GjsI--