Re: cursor already in use error

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: Sim Zacks <sim(at)compulab(dot)co(dot)il>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cursor already in use error
Date: 2005-03-02 09:55:59
Message-ID: 42258DAF.1020004@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sim Zacks wrote:
> create or replace function testcursor(thistestid int) returns varchar as
> $$
> declare
> crs Cursor for select comments from test a join test2 b on
> a.testid=b.testid where a.TestID=thistestid;
> thiscomment varchar;
> totalstr varchar;
> begin
> open crs;
> fetch crs into thiscomment;
> totalstr:='';
> while found loop
> totalstr:= totalstr || '-' || thiscomment;
> fetch crs into thiscomment;
> end loop;

close crs;

> return totalstr;
> end;
> $$language 'plpgsql';
>
> select name,testcursor(testid) from test; --doesn't work
> select name,testcursor(testid) from test where testid=1; -- works (as does
> testid=2 or 3)

The second query works because you fetch only one record; You don't call
the SP a second time with the cursor still open, while you do with the
first query.

Always close your cursors.

--
Alban Hertroys
MAG Productions

T: +31(0)53 4346874
F: +31(0)53 4346876
E: alban(at)magproductions(dot)nl
W: http://www.magproductions.nl

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2005-03-02 10:02:28 Re: cursor already in use error
Previous Message Michael Fuhr 2005-03-02 09:53:37 Re: cursor already in use error