Re: transaction problem using cursors - Mailing list pgsql-general

From Tom Lane
Subject Re: transaction problem using cursors
Date
Msg-id 17647.1181582470@sss.pgh.pa.us
Whole thread Raw
In response to Re: transaction problem using cursors  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-general
Gregory Stark <stark@enterprisedb.com> writes:
> "Pit M." <fmi-soft@gmx.de> writes:
>> The goal is to maintain a valid cursor that can be used to FETCH other records.
>> It would be ideal to skip this record an continue fetching the next record ->
>> but how can i achieve this?

> Well ideally the answer would be to wrap each FETCH in a savepoint and roll
> back to the savepoint if it fails. However I just tried it and this doesn't
> work. So I think the answer is you can't, sorry.

The problem is to distinguish failures that don't imply the cursor
itself is broken from failures that do.  What I'd suggest is reducing
the cursor definition to a simple "SELECT * FROM ..." and then doing
the failure-prone calculations separately.  The cursor won't get marked
PORTAL_FAILED unless the error occurs during a FETCH from it.

            regards, tom lane

pgsql-general by date:

Previous
From: Gregory Stark
Date:
Subject: Re: Materializing the relation
Next
From: Greg Smith
Date:
Subject: Re: When should I worry?