X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 4E9FD9FA3D7 for ; Wed, 14 Jun 2006 15:29:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 53631-02 for ; Wed, 14 Jun 2006 15:28:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by postgresql.org (Postfix) with ESMTP id 64BCF9FA5FB for ; Wed, 14 Jun 2006 15:28:51 -0300 (ADT) Received: from [213.162.97.75] (helo=mail.metronet.co.uk) by ptb-relay03.plus.net with esmtp (Exim) id 1Fqa6d-0005Vm-E4; Wed, 14 Jun 2006 19:28:43 +0100 Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 3C5FF7360A; Wed, 14 Jun 2006 19:28:39 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id D247315EA6; Wed, 14 Jun 2006 19:28:38 +0100 (BST) Message-ID: <44905556.2060506@archonet.com> Date: Wed, 14 Jun 2006 19:28:38 +0100 From: Richard Huxton User-Agent: Thunderbird 1.5.0.4 (X11/20060516) MIME-Version: 1.0 To: Alexis Palma Espinosa Cc: pgsql-sql@postgresql.org Subject: Re: About sequences that works BAD !!!! References: <251EA6C55832BE4C80F868CC951BA8CE02764F94@ucixw2.uci.cu> In-Reply-To: <251EA6C55832BE4C80F868CC951BA8CE02764F94@ucixw2.uci.cu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/167 X-Sequence-Number: 25403 Alexis Palma Espinosa wrote: > Hello everyone: >=20 >=20 >=20 > We are working with serials fields and we found a problem with then: > When we insert in a table that has e unique restrict, and this makes > insert fails, the sequence increments anyway...=BFWhat we can do about > it? Nothing. The whole point of sequences is that they don't lock. They *do* = guarantee unique numbers, but they *do not* guarantee no gaps. If you really want a series of ID numbers with no gaps you'll want to do = something like: 1. Begin transaction 2. Lock table exclusively 3. Find highest existing ID (...ORDER BY id DESC LIMIT 1) 4. Add one to it 5. Store new row. 6. commit transaction, freeing the lock --=20 Richard Huxton Archonet Ltd