Re: How do concurrent inserts work? - Mailing list pgsql-novice

From Serge Fonville
Subject Re: How do concurrent inserts work?
Date
Msg-id CAOAS_+LEe9dxq=vCf_oOBTrB10b-YurxT9WmLD0ocwFD0ajkOA@mail.gmail.com
Whole thread Raw
In response to How do concurrent inserts work?  (Yaroslav <ladayaroslav@yandex.ru>)
Responses Re: How do concurrent inserts work?  (Yaroslav <ladayaroslav@yandex.ru>)
List pgsql-novice
Hi,

Perhaps because your second session doesn't specify an isolation level?

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl

2014-12-27 11:11 GMT+01:00 Yaroslav <ladayaroslav@yandex.ru>:
Hi. After reading this:

http://postgresql.nabble.com/Re-BUG-12330-ACID-is-broken-for-unique-constraints-td5832085.html

I've come to conclusion that I don't understand PostgreSQL transaction
isolation. :(

Here's the example:
> CREATE TABLE t(a INT PRIMARY KEY);
> INSERT INTO t VALUES(1);

-- Test number 1:
> START TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> SAVEPOINT a;
> INSERT INTO t VALUES(1);
-- This results in 'duplicate key' error, so I reason there is a row with
this value, check it:
> ROLLBACK TO SAVEPOINT a;
> SELECT * FROM t WHERE a = 1;
1 -- 1 row. So yes, there is such row.
> COMMIT; -- done with this test


-- Test number 2:
> START TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> SELECT * FROM t WHERE a = 1;
1 -- 1 row
> SAVEPOINT a;

In other session> INSERT INTO t VALUES(2);
-- Back to my session:
> INSERT INTO t VALUES(2);
-- This results in 'duplicate key' error, so I reason there is a row with
this value, check it:
> ROLLBACK TO SAVEPOINT a;
> SELECT * FROM t WHERE a = 2;
-- 0 rows
-- So, I reason... Stop, what? Error told me that there IS such row, but now
I see there ISN'T?!

Can you enlighten me?




-----
WBR, Yaroslav Schekin.
--
View this message in context: http://postgresql.nabble.com/How-do-concurrent-inserts-work-tp5832157.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


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

pgsql-novice by date:

Previous
From: Yaroslav
Date:
Subject: How do concurrent inserts work?
Next
From: Yaroslav
Date:
Subject: Re: How do concurrent inserts work?