Re: UPSERT - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: UPSERT
Date
Msg-id 1173016494.3132.12.camel@localhost.localdomain
Whole thread Raw
In response to Re: UPSERT  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-hackers
Ühel kenal päeval, P, 2007-03-04 kell 07:46, kirjutas Bruno Wolff III:
> On Sun, Mar 04, 2007 at 14:55:47 +0200,
>   Hannu Krosing <hannu@skype.net> wrote:
> > 
> > UPDATE
> > IF NOT FOUND THEN 
> >   INSERT
> >   IF DUPLICATE KEY THEN
> >     UPDATE
> >   END IF
> > END IF
> 
> I believe it is possible for the above to fail. For example another
> transaction could create a matching record between the update and insert
> and then another transaction could delete it between the insert and the
> second update.

Then we may do the second part as a loop and hope that eventually we hit
the right point with either INSERT or UPDATE:
UPDATEWHILE NOT FOUND THEN   INSERT  IF DUPLICATE KEY THEN    UPDATE  END IFEND WHILE

-- 
----------------
Hannu Krosing
Database Architect
Skype Technologies OÜ
Akadeemia tee 21 F, Tallinn, 12618, Estonia

Skype me:  callto:hkrosing
Get Skype for free:  http://www.skype.com



pgsql-hackers by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: UPSERT
Next
From: Petr Jelinek
Date:
Subject: Re: UPSERT