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 1tmx5N-000WrK-CQ for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2025 15:43:05 +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 1tmx5M-004A7M-At for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2025 15:43:04 +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 1tmx5L-004A7E-W5 for pgsql-general@lists.postgresql.org; Tue, 25 Feb 2025 15:43:04 +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 1tmx5J-0001TB-0i for pgsql-general@lists.postgresql.org; Tue, 25 Feb 2025 15:43:03 +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 51PFh0vR1597772; Tue, 25 Feb 2025 10:43:00 -0500 From: Tom Lane To: Laurenz Albe cc: =?UTF-8?Q?=D0=9E=D0=BB=D0=B5=D0=B3_?= =?UTF-8?Q?=D0=A1=D0=B0=D0=BC=D0=BE=D0=B9=D0=BB=D0=BE=D0=B2?= , "pgsql-general@lists.postgresql.org" Subject: Re: How to return seto records from seof record function? In-reply-to: References: <56861740492680@mail.yandex.ru> Comments: In-reply-to Laurenz Albe message dated "Tue, 25 Feb 2025 15:47:23 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1597770.1740498180.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 25 Feb 2025 10:43:00 -0500 Message-ID: <1597771.1740498180@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Tue, 2025-02-25 at 17:15 +0300, =D0=9E=D0=BB=D0=B5=D0=B3 =D0=A1=D0=B0= =D0=BC=D0=BE=D0=B9=D0=BB=D0=BE=D0=B2 wrote: >> How to return seto records from seof record function? I tried pg_backgr= ound extension: > You need to be specific: > SELECT * FROM pg_background_result(l_id) AS (col1 integer, col2 text, = ...); > I don't think there is a way to get a generic "record" as result. > And even if you could, you would still have to specify a column list > when you call autonomous(). plpgsql is indeed not too friendly to this, but perhaps a SQL-language function would serve. That infrastructure seems to be okay with wrapping a generic setof-record result: regression=3D# \sf array_to_set CREATE OR REPLACE FUNCTION public.array_to_set(anyarray) RETURNS SETOF record LANGUAGE sql IMMUTABLE AS $function$ select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i $function$ regression=3D# create or replace function wrapper(anyarray) RETURNS SETOF record LANGUAGE sql as $$ select 1; select array_to_set($1); $$; CREATE FUNCTION regression=3D# select wrapper(array[44,55,66]); wrapper = --------- (1,44) (2,55) (3,66) (3 rows) regards, tom lane