| From: | "Aaron Bono" <postgresql(at)aranya(dot)com> |
|---|---|
| To: | "David Clarke" <pigwin32(at)gmail(dot)com> |
| Cc: | "operationsengineer1(at)yahoo(dot)com" <operationsengineer1(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Alternative to serial primary key |
| Date: | 2006-07-06 21:43:48 |
| Message-ID: | bf05e51c0607061443t2eb0cbbfl569b7b25c74166d7@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On 7/6/06, David Clarke <pigwin32(at)gmail(dot)com> wrote:
>
>
> 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.
So if you have:
addresses
address_id bigserial (pk),
address
person
person_id bigserial (pk),
first_name,
last_name,
address_id
you can do something like
INSERT INTO person (
address_id
)
SELECT
'Joe',
'Blow',
address_id
FROM addresses
WHERE addresses.address = ?;
No regeneration of PK necessary. If you index addresses.address the insert
should run quickly, right?
-Aaron Bono
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Sander Steffann | 2006-07-06 21:45:37 | Re: Alternative to serial primary key |
| Previous Message | D'Arcy J.M. Cain | 2006-07-06 21:18:16 | Re: Alternative to serial primary key |