Re: returning a recordset from PLpg/SQL

From: Richard Huxton <dev(at)archonet(dot)com>
To: terence(dot)kearns(at)canberra(dot)edu(dot)au
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: returning a recordset from PLpg/SQL
Date: 2004-06-09 08:58:40
Message-ID: 40C6D140.8010701@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2004-06-09 09:01:46 Re: Triggers
Previous Message Richard Huxton 2004-06-09 07:22:37 Re: Last insert id