Re: Solution to UPDATE...INSERT problem

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Solution to UPDATE...INSERT problem
Date: 2003-03-27 06:55:53
Message-ID: 001901c2f42d$e8fd5f60$6500a8c0@fhp.internal
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-03-27 07:13:28 Re: Solution to UPDATE...INSERT problem
Previous Message Tom Lane 2003-03-27 06:41:29 Re: [HACKERS] Solution to UPDATE...INSERT problem

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-03-27 07:13:28 Re: Solution to UPDATE...INSERT problem
Previous Message Tom Lane 2003-03-27 06:41:29 Re: [HACKERS] Solution to UPDATE...INSERT problem