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

From Christopher Kings-Lynne
Subject Re: Solution to UPDATE...INSERT problem
Date
Msg-id 001901c2f42d$e8fd5f60$6500a8c0@fhp.internal
Whole thread Raw
In response to Solution to UPDATE...INSERT problem  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Responses Re: Solution to UPDATE...INSERT problem  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
> Uh, why exactly do you think this is race-free?
>
> It looks fancy, but AFAICS the SELECT will return info that is correct
> as of its starting timestamp; which is not enough to guarantee that the
> INSERT won't conflict with another transaction doing the same thing
> concurrently.

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?

Chris



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Solution to UPDATE...INSERT problem
Next
From: Tom Lane
Date:
Subject: Re: Solution to UPDATE...INSERT problem