Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 5A8B89FBDF5 for ; Tue, 17 Jul 2007 12:40:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 92440-01 for ; Tue, 17 Jul 2007 12:40:49 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 675199FBDB5 for ; Tue, 17 Jul 2007 12:40:47 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IApA7-0003qg-64 for pgsql-sql@postgresql.org; Tue, 17 Jul 2007 17:40:31 +0200 Received: from smcgraw.ppp.frii.com ([216.17.133.158]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Jul 2007 17:40:31 +0200 Received: from smcg2297 by smcgraw.ppp.frii.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Jul 2007 17:40:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: "Stuart" Subject: Re: data dependent sequences? Date: Tue, 17 Jul 2007 09:40:21 -0600 Lines: 28 Message-ID: References: <1184515497.5778.141.camel@localhost.localdomain> <20070717150046.GC21688@phlogiston.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: smcgraw.ppp.frii.com X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1896 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/102 X-Sequence-Number: 28837 "Andrew Sullivan" wrote in message news:20070717150046.GC21688@phlogiston.dyndns.org... > On Tue, Jul 17, 2007 at 07:34:26AM -0600, Stuart wrote: > > I am not looking for gapless sequences. The reason I > > want to do this is the "typ" column is actually an indicator > > of the source of the rest of the infomation in the row. > > Why do you need the sequence to be 1. . .n for each typ, then? If > they're just there to preserve order, one sequence will work just > fine. Otherwise, I think you have a normalisation problem. I probably shouldn't have indicated that 'typ' was part of the PK, or named the other column 'id'. There is actually a separate (surrogate) PK, and there is a unique index on the on (id,typ) only to prevent accidental dupicates. So 'id' is not really structually important -- it is a value that exists soley for the UI. In the app, the user can explicity request an explicit 'id' value. My desire to use a sequence to assign them is to handle the 99% common case where the user doesn't care about assigning a specific id, and just wants the "next" resonable value, consistent with the other values for that typ row. If there are 3 rows of typ=20 and 2000000 rows of typ=21, I don't want the next typ=20 row to get an id of 2000004, when the other rows have values of 1,2,3. This is simply a user expectation, based on existing data, that I can't change. I would just prefer to implement it in the database if possible rather than than the app. Hope I have clarified a little :-)