Re: duplicate key violates unique constraint - Mailing list pgsql-general

From Richard Huxton
Subject Re: duplicate key violates unique constraint
Date
Msg-id 42ADAAFB.30404@archonet.com
Whole thread Raw
In response to Re: duplicate key violates unique constraint  (Csaba Nagy <nagy@ecircle-ag.com>)
Responses Re: duplicate key violates unique constraint  (Csaba Nagy <nagy@ecircle-ag.com>)
List pgsql-general
Csaba Nagy wrote:
> [snip]
>
>>If you have more than one client, this can always happen. You have two
>>choices:
>>  1. Use a lock to stop two clients interacting like this
>
>
> This won't work unless you make all the clients serialized, or you have
> all the ip's already inserted in the data base... you can't lock on an
> unknown key, otherwise the locking will also need to insert, and you're
> back to the same race condition ;-)

You can, however, have something more finely-grained than whole-table
locking (assuming one IP updated/inserted at a time) by filling a dummy
table with e.g. integers 0..255 and locking a row there based on (e.g.)
the last octet of your target IP.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Csaba Nagy
Date:
Subject: Re: duplicate key violates unique constraint
Next
From: Csaba Nagy
Date:
Subject: Re: duplicate key violates unique constraint