From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
Cc: | Олег Самойлов <splarv(at)ya(dot)ru>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: How to return seto records from seof record function? |
Date: | 2025-02-25 15:43:00 |
Message-ID: | 1597771.1740498180@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Sakshi Behl | 2025-02-25 17:19:39 | Re: PgSQL - SIEM Integration |
Previous Message | Alexander Farber | 2025-02-25 15:40:22 | Re: Azure Database for PostgreSQL flexible server vs other Azure offerings |