Re: second DML operation fails with updatable cursor - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: second DML operation fails with updatable cursor
Date
Msg-id 471F69FE.5000500@enterprisedb.com
Whole thread Raw
In response to Re: second DML operation fails with updatable cursor  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: second DML operation fails with updatable cursor
List pgsql-hackers
Tom Lane wrote:
> Heikki Linnakangas <heikki@enterprisedb.com> writes:
>> That would solve the problem with two updates of the same row, but not this:
>> UPDATE .. WHERE CURRENT OF...
>> FETCH RELATIVE 0
> 
>> At the moment, that returns the next row, not the one that was updated.
>> Same problem with FETCH NEXT + FETCH PRIOR after the UPDATE.
> 
> Hmm, what I'm seeing is that it returns the original (unmodified) row;
> is that what you meant to say?

No, that's not what I meant. Here's what I get:

postgres=# CREATE TABLE foo (id integer);
CREATE TABLE
postgres=# INSERT INTO foo SELECT a from generate_series(1,100) a;
INSERT 0 100
postgres=# BEGIN;
BEGIN
postgres=# DECLARE c CURSOR FOR SELECT id FROM foo FOR UPDATE;
DECLARE CURSOR
postgres=# FETCH 2 FROM c;id
---- 1 2
(2 rows)

postgres=# UPDATE foo set ID=20 WHERE CURRENT OF c;
UPDATE 1
postgres=# FETCH RELATIVE 0 FROM c;id
---- 3
(1 row)

I was expecting to get 20.

I do get the original unmodified tuple (2) if I leave out the FOR UPDATE.

--  Heikki Linnakangas EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: tomas@tuxteam.de
Date:
Subject: Re: Feature Freeze date for 8.4
Next
From: Tom Lane
Date:
Subject: Re: Feature Freeze date for 8.4