Re: Alternative to serial primary key

Поиск
Список
Период
Сортировка
От Aaron Bono
Тема Re: Alternative to serial primary key
Дата
Msg-id bf05e51c0607061443t2eb0cbbfl569b7b25c74166d7@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Alternative to serial primary key  ("David Clarke" <pigwin32@gmail.com>)
Ответы Re: Alternative to serial primary key
Список pgsql-sql
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

В списке pgsql-sql по дате отправления:

Предыдущее
От: "D'Arcy J.M. Cain"
Дата:
Сообщение: Re: Alternative to serial primary key
Следующее
От: "Sander Steffann"
Дата:
Сообщение: Re: Alternative to serial primary key