Re: UUID/GUID information

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: UUID/GUID information
Дата
Msg-id 200205301139.20519.josh@agliodbs.com
обсуждение исходный текст
Ответ на UUID/GUID information  (David Busby <Busby@pnts.com>)
Список pgsql-php
David,

>     I'm trying to migrate my MS-SQL(shit) to Postgre.  My database
> depends on having a uniqueidentifier for all objects stored. (20 or so
> tables of these unique objects).  In MS-SQL I can use this datatype called
> "uniqueidentifier" to accomplish this.  What would be a similar solution in
> Postgre?  I've looked on through the MAN pages and also scoured the net for
> this info...I don't necessarly need a UUID like the MS one but some unique
> way to identifiy each object.

The best way to do this in PostgreSQL is to set up an independant sequence:

CREATE SEQUENCE universal_sq;

Then reference this in each table definition:
CREATE TABLE blah (
    UUID INT4 NOT NULL DEFAULT NEXTVAL('universal_sq'),
    etc ...
);

CREATE TABLE neh (
    UUID INT4 NOT NULL DEFAULT NEXTVAL('universal_sq'),
    etc ...
);

You can even use the UUID as the primary key this way.  Postgres Sequence
manager insures that no sequence number is used twice, even in the event of
aborted transactions.  See the docs on sequences for more info.

Please note that special measures need to be taken if you are likely to exceed
the limits of INT4 (2.4 billion objects).

--
-Josh Berkus


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

Предыдущее
От: Keary Suska
Дата:
Сообщение: Re: UUID/GUID information
Следующее
От: David Busby
Дата:
Сообщение: Re: UUID/GUID information