Re: Strange result using transactions - Mailing list pgsql-general

From Stuart Cooper
Subject Re: Strange result using transactions
Date
Msg-id 7fc8628a0703262023u16970753o7d43d37a42d30b@mail.gmail.com
Whole thread Raw
In response to Strange result using transactions  ("Matthijs Melissen" <melissen@phil.uu.nl>)
List pgsql-general
> I am executing the following queries (id has a unique key):

> 1) begin;
> 1) delete from forum where id = 20;
> 1) insert into forum (id, name) values (20, 'test');
> 2) delete from forum where id = 20;
> 1) commit;

If you do these side by side in interactive psql sessions, you'll see that the
process 2) delete from forum where id=20; waits and waits and doesn't start
until you commiut process 1). So from the point of view of Process 2,
it sees the committed forum table and it has no entries in the forum table with
id 20, hence DELETE 0 is its output.

So the effective sequence of events is:
1) begin;
1) delete from forum where id = 20;
1) insert into forum (id, name) values (20, 'test');
1) commit;
2) delete from forum where id = 20;

Hope this helps,
Stuart.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_dump without psql rights
Next
From: Tom Lane
Date:
Subject: Re: Strange result using transactions