Re: How to return seto records from seof record function?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Олег Самойлов <splarv(at)ya(dot)ru>
Cc: "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 14:29:52
Message-ID: CAKFQuwY4BvZWfy=zrDYz4RtsTXUsaMb_ciVdyLnN20T8Kb5+bQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday, February 25, 2025, Олег Самойлов <splarv(at)ya(dot)ru> wrote:

> Postgresql 17.2
>
> How to return seto records from seof record function? I tried
> pg_background extension:
>
>
> *CREATE* *OR* *REPLACE* *FUNCTION* public.autonomous (p_script *text*)
>
> *RETURNS* *SETOF* record
>
> *LANGUAGE* plpgsql
>
> *VOLATILE* *STRICT* *PARALLEL* UNSAFE
>
> *AS* *$autonomous$*
>
> *DECLARE*
>
> l_id *integer*;
>
> *BEGIN*
>
> l_id := pg_background_launch(p_script);
>
> *RETURN* QUERY *SELECT* * *FROM* pg_background_result(l_id) *AS* (r record
> );
>
> *END*;
>
> *$autonomous$*;
>
>
>
> *SELECT** * **FROM* *autonomous**(**'SELECT now()'**) **AS** (**a*
> *timestamptz**)**;*
>
>
> SQL Error [42804]: ERROR: structure of query does not match function
> result type
> Detail: Returned type record does not match expected type timestamp with
> time zone in column 1.
> Where: SQL statement "SELECT * FROM pg_background_result(l_id) AS (r
> record)"
>
PL/pgSQL function autonomous(text) line 6 at RETURN QUERY
>

Interesting…not sure this can work as you have no way to know what the
caller has specified as the return data type in order to write the inner
generic function call correctly. Maybe you can convert the record result
to jsonb and return that?

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Олег Самойлов 2025-02-25 14:42:36 Re: How to return seto records from seof record function?
Previous Message Олег Самойлов 2025-02-25 14:15:15 How to return seto records from seof record function?