Re: cursors in plpgsql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tomasz Myrta <jasiek(at)klaster(dot)net>
Cc: Lista dyskusyjna pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: cursors in plpgsql
Date: 2003-09-17 21:13:13
Message-ID: 5920.1063833193@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tomasz Myrta <jasiek(at)klaster(dot)net> writes:
> I wanted to use some select result several times in pl/pgsql function.

> Neither move backward 10000 in test;
> nor
> execute ''move backward 10000 in test'';
> doesn't work.

Releases before 7.4 are spotty about supporting backwards scan of
complex queries --- if you have a join or aggregate in the query,
it likely won't work, yielding either strange errors or wrong answers.

It will work if the top plan node in the query is a SORT, though, so
a possible workaround is to add an explicit ORDER BY to the cursor's
query. (You will need to do some investigation with EXPLAIN to make
sure you are getting a suitable plan for the cursor.)

Or try 7.4 beta ...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-09-17 21:23:05 Re: [BUGS] session variable
Previous Message Tomasz Myrta 2003-09-17 20:46:08 cursors in plpgsql