0 Replies - 1582 Views - Last Post: 20 January 2009 - 09:49 AM

#1 Trogdor   User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

POSTGRESQL using GUIDs in postgres

Posted 20 January 2009 - 09:49 AM

Description: Starting at postgres 8 you can use the UUID datatype to store GUIDs. Unfortunately the GUIDs are not generated by postgres. Since it is impossible to guarantee a GUIDs uniqueness anyway, this simple way of generating them is as good as any. Just hash up the sequence with the current time and cast the 128 bit result to a UUID. easy peasy.postgres does not generate GUIDs but can store them. You can generate them yourself.
CREATE TABLE test
(
  id serial NOT NULL,
  guid uuid DEFAULT (md5(((currval('test_id_seq'::regclass) || ''::text) || now())))::uuid,
  x character(1)
)
WITH (OIDS=FALSE);

INSERT INTO test(x) VALUES('x');

SELECT * FROM test;



Is This A Good Question/Topic? 0
  • +

Page 1 of 1