Re: Alternative to serial primary key

From: "David Clarke" <pigwin32(at)gmail(dot)com>
To: "operationsengineer1(at)yahoo(dot)com" <operationsengineer1(at)yahoo(dot)com>
Cc: "Aaron Bono" <postgresql(at)aranya(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Alternative to serial primary key
Date: 2006-07-06 20:30:57
Message-ID: 12b7ac1e0607061330o34adbd6ds9bd624d3889c7fe7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 7/7/06, operationsengineer1(at)yahoo(dot)com <operationsengineer1(at)yahoo(dot)com> wrote:
> i agree. all my primary keys are abstract - even
> though some don't have to be. iow, i'm comfortable
> using serials as my primary key even when i don't
> absolutely need to.

Yes I had in fact already created my table using a serial as the
primary key but I've been reading Celko's SQL Programming Style and
the use of a hash on the address column as the primary key (and for
use in FK's) meets a number of the requirements for a good key. The
address column itself is the natural primary key but it doesn't make
for a good FK. Plus I feel I would be remiss in not exploring an
alternative to the serial key.

To recap, yes there is only a single column, yes it is varchar. I need
to do a lookup on the address column which is unique and use it as a
foreign key in other tables. Using a serial id would obviously work
and has been recommended. But having a hash function over the address
column as the primary key means I can always regenerate my primary key
from the data which is impossible with a serial key. I believe the
risk of collision using md5 is effectively zero on this data and I can
put a unique index over it.

I'm kind of new to sql so apologies if this is a naive approach.
Thanks to all for responses.

Dave

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message D'Arcy J.M. Cain 2006-07-06 21:18:16 Re: Alternative to serial primary key
Previous Message Aaron Bono 2006-07-06 19:32:45 Re: Foreign Key: what value?