Re: Re: Why is unique constraint needed for upsert? (treat atomicity as optional)

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: Why is unique constraint needed for upsert? (treat atomicity as optional)
Date: 2014-07-23 22:45:42
Message-ID: 53D03B16.9020503@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 7/23/2014 3:29 PM, Seamus Abshere wrote:
> My argument lives and dies on the assumption that UPSERT would be
> useful even if it was (when given with no options) just a macro for
>
>> UPDATE db SET b = data WHERE a = key;
>> IF NOT found THEN
>> INSERT INTO db(a,b) VALUES (key, data);
>> END IF;

but that won't work if two connections execute similar 'upserts'
concurrently. both updates will see the record isn't there, then one
or the other insert will fail, depending on which transaction commits first.

--
john r pierce 37N 122W
somewhere on the middle of the left coast

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G Johnston 2014-07-23 22:57:01 Re: Why is unique constraint needed for upsert? (treat atomicity as optional)
Previous Message Krystian Bigaj 2014-07-23 22:29:41 Re: System shutdown signal on Windows (was Re: [GENERAL])