cursors FOR UPDATE don't return most recent row

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: cursors FOR UPDATE don't return most recent row
Date: 2012-01-26 04:03:20
Message-ID: 1327536411-sup-7848@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


This is my test case (all in one session):

CREATE TABLE foo (
key int PRIMARY KEY,
value int
);

INSERT INTO foo VALUES (1, 1);

BEGIN;
DECLARE foo CURSOR FOR SELECT * FROM foo FOR UPDATE;
UPDATE foo SET value = 2 WHERE key = 1;
UPDATE foo SET value = 3 WHERE key = 1;
FETCH 1 FROM foo;
COMMIT;

I expected the FETCH to return one row, with the latest data, i.e.
(1, 3), but instead it's returning empty.

If instead I run both UPDATEs in another session, then I do get

alvherre=# FETCH 1 FROM foo;
key | value
-----+-------
1 | 3
(1 fila)

Is this intended?

--
Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2012-01-26 04:22:26 Re: WAL Restore process during recovery
Previous Message Noah Misch 2012-01-26 03:39:56 Re: Avoid FK validations for no-rewrite ALTER TABLE ALTER TYPE