Re: plpgsql functions

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: c k <shreeseva(dot)learning(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: plpgsql functions
Date: 2008-08-15 20:47:48
Message-ID: 48A5EB74.8030804@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 15/08/2008 20:12, c k wrote:
> Hi,
> I am getting an error for a function written in plpgsql, as -
>
> CREATE OR REPLACE FUNCTION uf_accgroupbal(date, date, p_company integer)
> RETURNS SETOF uf_closingbal AS

<snip>

For functions return SETOF any type, you need to use the following idiom:

...
declare
rec yourtype;
begin
for rec in [your query here...]
loop
return next rec;
end loop;
return;
end;
...

See the docs on control structures in pl/pgsql.

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message F. Jovan Jester 2008-08-15 21:27:02 Re: Horology test failure while compiling PostgreSQL 8.3.3 on Solaris 10 x64
Previous Message Raymond O'Donnell 2008-08-15 20:40:32 Re: syntax error at or near "PERFORM"