public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Laurenz Albe <[email protected]>
Cc: Олег Самойлов <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: How to return seto records from seof record function?
Date: Tue, 25 Feb 2025 10:43:00 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>

Laurenz Albe <[email protected]> writes:
> On Tue, 2025-02-25 at 17:15 +0300, Олег Самойлов wrote:
>> How to return seto records from seof record function? I tried pg_background 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=# \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=# create or replace function wrapper(anyarray)
RETURNS SETOF record LANGUAGE sql as
$$ select 1; select array_to_set($1); $$;
CREATE FUNCTION

regression=# select wrapper(array[44,55,66]);
 wrapper 
---------
 (1,44)
 (2,55)
 (3,66)
(3 rows)

			regards, tom lane






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: How to return seto records from seof record function?
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox