Re: Revisited: Transactions, insert unique. - Mailing list pgsql-general

From Lincoln Yeoh
Subject Re: Revisited: Transactions, insert unique.
Date
Msg-id 3.0.5.32.20000425155652.008dbb60@pop.mecomb.po.my
Whole thread Raw
In response to Re: Revisited: Transactions, insert unique.  (Mike Mascari <mascarm@mascari.com>)
List pgsql-general
At 10:17 PM 24-04-2000 -0400, Mike Mascari wrote:
>Lincoln Yeoh wrote:
>PostgreSQL implements SELECT...FOR UPDATE to allow for the
>sequence you'be described:
>
>Session 1:
>
>BEGIN;
>SELECT webuser FROM webusers WHERE webuser = 'webuser1';
>
>Session 2:
>
>BEGIN;
>UPDATE webusers SET webuser = 'webuser2' WHERE webuser =
>'webuser1';*

The 6.5.3 running on my site does not block for the case I described which
has an INSERT after the select.

begin;
select from mytable where field=value for update;
if rows=0 {
    insert into mytable (field,field2) values (value,value2);
} else {
    update mytable set field=value, field2=value2;
}
commit;

Tested on 6.5.3.
Did a select for update in two concurrent transactions, they did not block,
and both inserts went through (if there was a unique, one of the
transactions would have had to be rolled back and redone from scratch).

If the behaviour is different for 7.0, I'm interested!

Cheerio,

Link.


pgsql-general by date:

Previous
From: Fabrice Scemama
Date:
Subject: Re: Is 7.0 ready?
Next
From: "J. Atwood"
Date:
Subject: Re: [Zope] PyGres DB Connection in Zope drops when many Users are added (UserDB) (UserDB)