Re: atomic function

From: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
To: Mage <mage(at)mage(dot)hu>
Cc: Pgsql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: atomic function
Date: 2005-08-15 10:19:07
Message-ID: Pine.LNX.4.44.0508151215280.2995-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 15 Aug 2005, Mage wrote:

> 2005-08-12 19:08:43: ERROR: duplicate key violates unique constraint
> "common_adviewnum_adid_site_day_index"

Between your select and your insert someone else inserted a row making the
insert fail.

See this example of how you can update or insert depending on what is in
the table:

http://developer.postgresql.org/docs/postgres/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE

If you don't have 8.0 so you can do as the example you need to lock the
table so no one else can insert between your select and your insert.

--
/Dennis Björklund

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tino Wildenhain 2005-08-15 10:28:28 Re: atomic function
Previous Message Dennis Bjorklund 2005-08-15 10:11:09 Re: Optimizing query