X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 44EF052908 for ; Mon, 13 Jun 2005 12:59:38 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56526-09 for ; Mon, 13 Jun 2005 15:59:33 +0000 (GMT) Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200]) by svr1.postgresql.org (Postfix) with ESMTP id 7EEC352812 for ; Mon, 13 Jun 2005 12:59:32 -0300 (ADT) Received: from [192.168.1.110] (unknown [192.168.1.110]) by mail.ecircle.de (READY) with ESMTP id 5C65555D641; Mon, 13 Jun 2005 17:59:32 +0200 (CEST) Subject: Re: duplicate key violates unique constraint From: Csaba Nagy To: Richard Huxton Cc: "ON.KG" , Postgres general mailing list In-Reply-To: <42ADAAFB.30404@archonet.com> References: <42A95936.3060002@archonet.com> <20050610095655.0215752956@svr1.postgresql.org> <10813889593.20050613202239@on.kg> <42AD9B9D.6080902@archonet.com> <1118676122.2720.24.camel@coppola.muc.ecircle.de> <42ADAAFB.30404@archonet.com> Content-Type: text/plain Message-Id: <1118678332.2720.27.camel@coppola.muc.ecircle.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Mon, 13 Jun 2005 17:58:52 +0200 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.02 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/628 X-Sequence-Number: 79336 That would work indeed. Bit I guess the savepoint solution will be the simplest and fastest if the OP has or can install 8.0 version. Cheers, Csaba. On Mon, 2005-06-13 at 17:49, Richard Huxton wrote: > 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