pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14328: SELECT FOR UPDATE doesn't return existing row
3+ messages / 3 participants
[nested] [flat]

* BUG #14328: SELECT FOR UPDATE doesn't return existing row
@ 2016-09-19 16:01  imyfess@gmail.com
  0 siblings, 2 replies; 3+ messages in thread

From: imyfess@gmail.com @ 2016-09-19 16:01 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14328
Logged by:          Dima Pavlov
Email address:      imyfess@gmail.com
PostgreSQL version: 9.4.4
Operating system:   Windows 10
Description:        

SELECT FOR UPDATE returns 0 rows in scenario below. But if I just execute
sql query from second transaction it always returns 1 row.

ENVIRONMENT:
-------------
CREATE TABLE t1 (_pk serial, t1c1 integer, t1c2 integer, t1c3 text);
CREATE TABLE t2 (_pk serial, t2c1 text, t2c2 integer);
insert into t1 (t1c1, t1c2, t1c3) values(123456789, 100,
'string_value_1');
insert into t2 (t2c1, t2c2) values('string_value_2', 100);

TRANSACTION 1:
--------------
BEGIN;
-- This query updates t1c1 to its current value, it doesn't change
anything
UPDATE t1 SET t1c3 = 'string_value_1' WHERE t1c1 = 123456789;

-- Query returned successfully: one row affected, 51 msec execution time.


TRANSACTION 2:
--------------
WITH 
    cte1 AS (
        SELECT t2c2 FROM t2 WHERE t2c1 = 'string_value_2'
    ),

    cte2 AS (
        SELECT * FROM t1
        WHERE 
             t1c1 = 123456789 
            AND t1c2 = (SELECT t2c2 FROM cte1)
        FOR UPDATE
    ) 

SELECT * FROM cte2

-- Waiting


TRANSACTION 1:
--------------
COMMIT;

-- Query returned successfully with no result in 41 msec.


TRANSACTION 2:
--------------
-- Returned 0 rows




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14328: SELECT FOR UPDATE doesn't return existing row
@ 2016-09-19 16:18  Andomar <andomar@aule.net>
  parent: imyfess@gmail.com
  1 sibling, 0 replies; 3+ messages in thread

From: Andomar @ 2016-09-19 16:18 UTC (permalink / raw)
  To: imyfess@gmail.com; pgsql-bugs

I can reproduce this on 9.4 on Debian Linux.

This relates to a question on Stack Overflow: http://stackoverflow.com/q/39550510/50552

The row seems to be dropped from the result set after the query waits on the lock.

Cheers,
Andomar

> On 19 Sep 2016, at 18:01, imyfess@gmail.com wrote:
> 
> 14328

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14328: SELECT FOR UPDATE doesn't return existing row
@ 2016-09-22 15:36  Tom Lane <tgl@sss.pgh.pa.us>
  parent: imyfess@gmail.com
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2016-09-22 15:36 UTC (permalink / raw)
  To: imyfess@gmail.com; +Cc: pgsql-bugs

imyfess@gmail.com writes:
> SELECT FOR UPDATE returns 0 rows in scenario below. But if I just execute
> sql query from second transaction it always returns 1 row.

I've pushed a patch for this.  Thanks for the report!

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2016-09-22 15:36 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-09-19 16:01 BUG #14328: SELECT FOR UPDATE doesn't return existing row imyfess@gmail.com
2016-09-19 16:18 ` Andomar <andomar@aule.net>
2016-09-22 15:36 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox