Re: UUID/GUID information

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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



[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux