Re: INSERT ON DUPLICATE KEY UPDATE

From: jseymour(at)linxnet(dot)com (Jim Seymour)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT ON DUPLICATE KEY UPDATE
Date: 2004-06-18 20:41:46
Message-ID: 20040618204146.842EA4310@jimsun.linxnet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Robert Treat <xzilla(at)users(dot)sourceforge(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeroen T. Vermeulen 2004-06-18 20:46:17 Article on open-source databases
Previous Message Jeff Rogers 2004-06-18 20:40:53 Re: can't win