Re: Functions that return both Output Parameters and recordsets - Mailing list pgsql-general

From Tom Lane
Subject Re: Functions that return both Output Parameters and recordsets
Date
Msg-id 8674.1181570398@sss.pgh.pa.us
Whole thread Raw
In response to Re: Functions that return both Output Parameters and recordsets  (Jeremy Nix <Jeremy.Nix@sfsltd.com>)
List pgsql-general
Jeremy Nix <Jeremy.Nix@sfsltd.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: track ddl changes on single database
Next
From: "Pit M."
Date:
Subject: Re: transaction problem using cursors