Re: UUID/GUID information - Mailing list pgsql-php

From Josh Berkus
Subject Re: UUID/GUID information
Date
Msg-id 200205301139.20519.josh@agliodbs.com
Whole thread Raw
In response to UUID/GUID information  (David Busby <Busby@pnts.com>)
List 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 by date:

Previous
From: Keary Suska
Date:
Subject: Re: UUID/GUID information
Next
From: David Busby
Date:
Subject: Re: UUID/GUID information