pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: David Busby <Busby@pnts.com>
To: 'pgsql-php@postgresql.org' <pgsql-php@postgresql.org>
Subject: Re: UUID/GUID information
Date: Thu, 30 May 2002 11:39:20 -0700
Message-ID: <200205301139.20519.josh@agliodbs.com> (raw)
In-Reply-To: <35363AB30BF2D311B73C0050DAB989F063C1@SEAPDC01>
References: <35363AB30BF2D311B73C0050DAB989F063C1@SEAPDC01>


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




view thread (7+ messages)  latest in thread

Message-ID: <200205301139.20519.josh@agliodbs.com>
Permalink:  ../200205301139.20519.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200205301139.20519.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: josh@agliodbs.com, Busby@pnts.com
  Subject: Re: UUID/GUID information
  In-Reply-To: <200205301139.20519.josh@agliodbs.com>
  References: <35363AB30BF2D311B73C0050DAB989F063C1@SEAPDC01> <200205301139.20519.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox