Re: returning a recordset from PLpg/SQL - Mailing list pgsql-sql

From Richard Huxton
Subject Re: returning a recordset from PLpg/SQL
Date
Msg-id 40C6D140.8010701@archonet.com
Whole thread Raw
In response to returning a recordset from PLpg/SQL  (Terence Kearns <terencek@isd.canberra.edu.au>)
List pgsql-sql
Terence Kearns wrote:
> Looking at the datatypes you can RETURN, it doesn't seem that there is a 
> way to return a recordset
> 
> I tried
> RETURNS SETOF RECORD
> but that doesn't work
> 
> I even tried
> RETURNS SETOF fooTable%ROWTYPE
> 
> What I would like to do is not that simple, I need to be able to 
> build/declare a record definition with an arbitary list of columns and 
> then return a set of that record which has it's values populated by 
> queries and calculations inside the procedure.

Declare your datatype (CREATE TYPE ...) and return a SETOF that. What 
you can't do is declare your datatype inside your function. Clearly 
PostgreSQL needs to know what type is being returned while parsing the 
function, so you can't have a "dynamic type" (if such an idea has any 
meaning at all).

--   Richard Huxton  Archonet Ltd


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Last insert id
Next
From: Richard Huxton
Date:
Subject: Re: Triggers