Re: MERGE vs REPLACE

From: mark(at)mark(dot)mielke(dot)cc
To: Rod Taylor <pg(at)rbt(dot)ca>
Cc: josh(at)agliodbs(dot)com, Jaime Casanova <systemguards(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: MERGE vs REPLACE
Date: 2005-11-11 23:36:57
Message-ID: 20051111233657.GA13724@mark.mielke.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 11, 2005 at 06:00:32PM -0500, Rod Taylor wrote:
> So? That is what save points are for. You can even skip the select for
> update if you don't mind dead tuples from the attempted insert.
> SELECT ... FOR UPDATE;
> IF not exists THEN
> SAVEPOINT;
> INSERT ;
> IF UNIQUE VIOLATION THEN
> /* Someone else inserted between the SELECT and our INSERT */
> ROLLBACK TO SAVEPOINT;
> UPDATE;
> ELSE
> RELEASE SAVEPOINT;
> FI
> ELSE
> UPDATE;
> FI

Isn't there still a race between INSERT and UPDATE?

Low probability, for sure, as it would have had to not exist, then
exist, then not exist, but still possible.

I'd like a REPLACE that could be safe, or at least cause a COMMIT to
fail, for this reason.

Cheers,
mark

--
mark(at)mielke(dot)cc / markm(at)ncf(dot)ca / markm(at)nortel(dot)com __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada

One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...

http://mark.mielke.cc/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Eric Lauzon 2005-11-12 00:12:00 (View and SQL) VS plpgsql
Previous Message Gavin Sherry 2005-11-11 23:23:56 Re: MERGE vs REPLACE