Re: Functions that return both Output Parameters and recordsets

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeremy Nix <Jeremy(dot)Nix(at)sfsltd(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Functions that return both Output Parameters and recordsets
Date: 2007-06-11 13:59:58
Message-ID: 8674.1181570398@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeremy Nix <Jeremy(dot)Nix(at)sfsltd(dot)com> writes:
> I see what you're doing, but I'm not quite sure how to adapt it to what
> I'm doing. Here's simplified snippet of my code. Can elaborate on how
> I can return a recordset and the output parameters.?

I suppose what you need is something like

CREATE OR REPLACE FUNCTION Search (OUT TotalRecords int, OUT TotalPages int)
RETURNS SETOF record AS
$BODY$
FOR myRecord IN
SELECT cols FROM searchResults
LOOP
TotalRecords := myRecord.TotalRecords;
TotalPages := myRecord.TotalPages;
RETURN NEXT;
END LOOP;

Anyway the point is that when you are using OUT parameters you do not
say anything in RETURN or RETURN NEXT. Whatever you last assigned to
the parameter variables is what's returned.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pit M. 2007-06-11 14:03:19 Re: transaction problem using cursors
Previous Message Tom Lane 2007-06-11 13:55:13 Re: track ddl changes on single database