Re: Solution to UPDATE...INSERT problem - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Solution to UPDATE...INSERT problem
Date
Msg-id 9715.1048749208@sss.pgh.pa.us
Whole thread Raw
In response to Re: Solution to UPDATE...INSERT problem  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
List pgsql-hackers
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au> writes:
>> Uh, why exactly do you think this is race-free?

> How about:

> INSERT INTO table SELECT 1, 'foo' WHERE NOT EXISTS (SELECT TRUE FROM table
> WHERE pkcol=1 FOR UPDATE);

> It's a lot more straightforward and has a FOR UPDATE.  Can this still cause
> unique constraint failures?

Certainly.  FOR UPDATE locks an existing row; it cannot lock the
condition of non-existence of a row.
        regards, tom lane



pgsql-hackers by date:

Previous
From: "Christopher Kings-Lynne"
Date:
Subject: Re: Solution to UPDATE...INSERT problem
Next
From: Hiroshi Inoue
Date:
Subject: Re: updateable cursors & visibility