Re: INSERT ON DUPLICATE KEY UPDATE - Mailing list pgsql-general

From jseymour@linxnet.com (Jim Seymour)
Subject Re: INSERT ON DUPLICATE KEY UPDATE
Date
Msg-id 20040618204146.842EA4310@jimsun.linxnet.com
Whole thread Raw
In response to Re: INSERT ON DUPLICATE KEY UPDATE  (Robert Treat <xzilla@users.sourceforge.net>)
Responses Re: INSERT ON DUPLICATE KEY UPDATE
List pgsql-general
Robert Treat <xzilla@users.sourceforge.net> wrote:
>
[snip]
>
> IIRC the main downside to the select/update method is it introduces a
> race condition that can only be solved by locking the table; not an
> issue for most my$ql apps but would be frowned upon by most postgresql
> users.
[snip]

One way around the race condition is to insert and, if the insert
fails, do an update.  If that fails, then something is actually wrong.

One caveat regarding the above solution: Even when an insert fails, if
there's a column with a sequence in it, that sequence will be
incremented nonetheless.

Jim


pgsql-general by date:

Previous
From: Jeff Rogers
Date:
Subject: Re: can't win
Next
From: Eduardo Pérez Ureta
Date:
Subject: Re: INSERT ON DUPLICATE KEY UPDATE