Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-hackers by date

Next:From: Fujii MasaoDate: 2012-01-26 04:22:26
Subject: Re: WAL Restore process during recovery
Previous:From: Noah MischDate: 2012-01-26 03:39:56
Subject: Re: Avoid FK validations for no-rewrite ALTER TABLEALTER TYPE

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group