Re: not so sequential sequences

From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: not so sequential sequences
Date: 2006-10-17 22:26:10
Message-ID: 60irii7f5p.fsf@dba2.int.libertyrms.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

rhys(dot)stewart(at)gmail(dot)com ("Rhys Stewart") writes:
> Hi all, looking for a method to number a table sequentially, but the
> sequence only increments if the value in a certain column is
> different. as in
>
>
> seq | parish
> ------------------------
> 1 | Kingston
> 1 | Kingston
> 1 | Kingston
> 1 | Kingston
> 2 | Lucea
> 3 | Morant Bay
> 3 | Morant Bay
> 3 | Morant Bay
> 4 | Port Antonio
> 5 | Savannah-La-Mar
> 5 | Savannah-La-Mar
> 5 | Savannah-La-Mar
>
> so i guess i would order by a certain column and then the 'magic
> sequence' would be a column that only increments when the column
> changes.

The usual way to do this would be to separate out what clearly is a
dependant table; the seq and parish values could be associated with a
smaller table that increments any time you get a new parish.

The process of doing this sort of separation is called "normalization."
<http://en.wikipedia.org/wiki/Database_normalization>
--
(reverse (concatenate 'string "gro.mca" "@" "enworbbc"))
http://linuxfinances.info/info/internet.html
Rules of the Evil Overlord #32. "I will not fly into a rage and kill a
messenger who brings me bad news just to illustrate how evil I really
am. Good messengers are hard to come by."
<http://www.eviloverlord.com/>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message James Cloos 2006-10-17 22:28:33 Re: Anyone using "POSIX" time zone offset capability?
Previous Message Shane Ambler 2006-10-17 22:05:54 Re: Database users Passwords