Re: [GENERAL] Fun with Cursors- how to rewind a cursor

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Postgres User <postgres(dot)developer(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [GENERAL] Fun with Cursors- how to rewind a cursor
Date: 2007-03-25 19:04:10
Message-ID: 9034.1174849450@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Tom Lane wrote:
>> Hm, you're right. This arises from the fact that _SPI_execute_plan
>> rejects cursor-related utility statements. While I'd never stopped
>> to question that before, it does seem like this restriction is a
>> bit pointless. Does anyone remember why it's like that?

> Is there anything to do on this item?

I dug in the archives and realized that SPI was originally written by
Vadim, not Jan as I'd been thinking, so there's nobody left on the
project who has any special insight into this. I found this message
describing it:
http://archives.postgresql.org/pgsql-hackers/1997-08/msg00338.php
wherein Vadim says

>>> 4. I have some code for server programming interface (SPI)
>>> which allows to run queries from user defined C-functions.
>>> With current postgres limitations (no nested transactions, cursors
>>> inside BEGIN/END only) SPI disallows using of BEGIN/END & cursors.
>>> It's bad for procedures but it's enough for triggers!

so it seems he saw this just as an implementation restriction
rather than a fundamental property of SPI. And I don't see
why cursors being within-transaction only means SPI shouldn't
touch them --- maybe he just wasn't thinking carefully about that.

I'd venture that we should try to get rid of the restriction, but I'm
unsure whether removing the error check is sufficient or whether there
are real problems it's preventing.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dmitry Koterov 2007-03-25 22:44:34 Re: Check the existance of temporary table
Previous Message Yonatan Ben-Nes 2007-03-25 18:52:26 Re: Tsearch2 can't be checked for equality?

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2007-03-25 19:04:53 Re: Idea for cleaner representation of snapshots
Previous Message Tom Lane 2007-03-25 18:20:32 Re: datestyle GUC broken in HEAD?