On 7/6/06,
David Clarke <
pigwin32@gmail.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