Re: Like to RETURN SQL results set - Mailing list pgsql-admin

From M Sarwar
Subject Re: Like to RETURN SQL results set
Date
Msg-id DM4PR19MB5978F71CFF8C6626DD0DD5F8D33B2@DM4PR19MB5978.namprd19.prod.outlook.com
Whole thread Raw
In response to Re: Like to RETURN SQL results set  (Laurenz Albe <laurenz.albe@cybertec.at>)
Responses Re: Like to RETURN SQL results set
List pgsql-admin
Laurenz:
Numbers of returning columns will vary  dynamically. 
Based on that SELECT * FROM func() AS (c1 integer, c2 text) is not applicable in my case.
Thanks,
Sarwar



From: Laurenz Albe <laurenz.albe@cybertec.at>
Sent: Thursday, March 28, 2024 5:19 AM
To: M Sarwar <sarwarmd02@outlook.com>; pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
Subject: Re: Like to RETURN SQL results set
 
On Wed, 2024-03-27 at 20:40 +0000, M Sarwar wrote:
> I am writing a dynamic function in which number of columns to be retrieved change
> depending on the parameter values passed while invoking the function.
> I am using CROSSTAB in the dynamic SQL.
> Once I prepare a dynamic SQL and I execute, I want the entire result set from
> the executed SQL to be returned to function RETURN.
> Is this possible? If yes, can you please point me to some examples.

No, this is not possible, unless you declare the function as "RETURNS SETOF record".
But then you have to specify the column list when you use the function, e.g.:

  SELECT * FROM func() AS (c1 integer, c2 text)

Yours,
Laurenz Albe

pgsql-admin by date:

Previous
From: Eduardo Barbachan
Date:
Subject: Re: Mssql to postgres migration
Next
From: Erik Wienhold
Date:
Subject: Re: Like to RETURN SQL results set