Re: UUID/GUID information

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: David Busby <Busby(at)pnts(dot)com>, "'pgsql-php(at)postgresql(dot)org'" <pgsql-php(at)postgresql(dot)org>
Subject: Re: UUID/GUID information
Date: 2002-05-30 18:39:20
Message-ID: 200205301139.20519.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-php by date

  From Date Subject
Next Message David Busby 2002-05-30 20:05:29 Re: UUID/GUID information
Previous Message Keary Suska 2002-05-30 18:31:38 Re: UUID/GUID information