0 Replies - 1756 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.
  id serial NOT NULL,
  guid uuid DEFAULT (md5(((currval('test_id_seq'::regclass) || ''::text) || now())))::uuid,
  x character(1)

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


Is This A Good Question/Topic? 0
  • +

Page 1 of 1