Re: How to prevent duplicate key error when two processes do DELETE/INSERT simultaneously?

From: Alex Hunsaker <badalex(at)gmail(dot)com>
To: Brodie Thiesfield <brofield+pgsql(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to prevent duplicate key error when two processes do DELETE/INSERT simultaneously?
Date: 2009-07-30 04:30:57
Message-ID: 34d269d40907292130n2cffd20g25baf9f8b51f530c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jul 29, 2009 at 19:53, Brodie
Thiesfield<brofield+pgsql(at)gmail(dot)com> wrote:
> On further investigation, since the logic requires the delete to be
> made first to get rid of other possible rows, so I'll go with:
>
> DELETE
> (if supported)  INSERT OR REPLACE
> (otherwise)             INSERT, if duplicate key, UPDATE
>

You can use plpgsql to emulate insert or replace (I think there are
some comments on emulating mysql specifically in the commented
versions of the docs somewhere... but thats up to you to find em) see
http://www.postgresql.org/docs/8.4/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
example 38-1

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2009-07-30 06:37:35 pg_stat_activity undocumented?
Previous Message Tom Lane 2009-07-30 03:43:37 Re: Blog post about Amazon Elastic Block Storage