Re: timestamp as primary key?

Поиск
Список
Период
Сортировка
От John D. Burger
Тема Re: timestamp as primary key?
Дата
Msg-id 02D2DC33-6383-46EF-BF53-4F64423DE2DB@mitre.org
обсуждение исходный текст
Ответ на Re: timestamp as primary key?  (Tomasz Ostrowski <tometzky@batory.org.pl>)
Ответы Re: timestamp as primary key?  (AgentM <agentm@themactionfaction.com>)
Список pgsql-general
cckramer wrote:

> I have table for online chat system that keep messages sent between
> users.

> Question: is it okay to use timestamp as primary key, or there is
> possibility of collision? (Meaning two processes may INSERT into table
> within same millisecond.) It is a web application.

tometzky wrote:

> If your insert fail you can always try again after some random short
> time.

But then the timestamp field does not accurately represent the actual
time of the event.  If you really want a primary key, and you really
don't want to just use a sequence default, I would make the key a
composite:

   PRIMARY KEY (user_id_from, user_id_to, message_time)

This should cut way down on the possibility of key collision.

- John D. Burger
   MITRE


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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Overload after some minutes, please help!
Следующее
От: Ray Stell
Дата:
Сообщение: Re: hardware failure - data recovery