Re: cursors from pl/pgsql - Mailing list pgsql-general

From Pavel Stehule
Subject Re: cursors from pl/pgsql
Date
Msg-id y2r162867791004062252qccc8498j9bc6d3e990654568@mail.gmail.com
Whole thread Raw
In response to cursors from pl/pgsql  (Marc Menem <marc.menem@m4x.org>)
List pgsql-general
Hello

2010/4/7 Marc Menem <marc.menem@m4x.org>:
> Hi all,
>
> I'm trying to use a cursor returned by a function from another function. But
> I can't seem to get it working correctly. The error message is:
>   ERROR:  cursor FOR loop must use a bound cursor variable
> I am not sure how to bind it;

you can't do it now. So use different cycle statement - WHILE a FETCH statement

regards

Pavel Stehule
>
> my code is similar to this:
>
> create or replace function store_normalize(groupid_in varchar(20)) RETURNS
> int AS $$
> DECLARE
>     outputcursor refcursor;
>     normrow_r record;
> BEGIN
>         perform normalize('outputcursor', groupid_in);
>         for normrow_r in outputcursor loop
>             insert into factordata(factorid, stockid, value, date)
>             values (normrow_r.factorid, normrow_r.stockid, normrow_r.value,
> normrow_r.date);
>         end loop;
>         close ouputcursor;
>         END LOOP;
>      return 1;
> END;
> $$ LANGUAGE plpgsql;
>
>
> CREATE OR REPLACE FUNCTION normalize(outputcursor refcursor,
>     groupid_in varchar(20)
> ) RETURNS refcursor AS $$
> BEGIN
>
> OPEN outputcursor FOR
> select * from factordata where groupid = groupid_in;
>
>     RETURN outputcursor;
> END;
> $$ LANGUAGE plpgsql;
>
> cheers.
> Marc
>

pgsql-general by date:

Previous
From: "Nikhil G. Daddikar"
Date:
Subject: Re: "1-Click" installer problems
Next
From: Dave Page
Date:
Subject: Re: "1-Click" installer problems