I have built some UUID generation functions using the library at
<http://www.ossp.org/pkg/lib/uuid/>. This should cover all the usual ways to
do it, and it also provides some special constants that could be useful.
I have attached the code, but the code is actually against 8.2 with uuid
defined as a domain over text, because I needed this functionality in a
current project. I will adjust the code for the real uuid type in 8.3 if
wanted.
What should I do with this? contrib?
Example output:
test=# select uuid_nil(); uuid_nil
--------------------------------------00000000-0000-0000-0000-000000000000
(1 row)
test=# select uuid_ns_dns(); uuid_ns_dns
--------------------------------------6ba7b810-9dad-11d1-80b4-00c04fd430c8
(1 row)
test=# select uuid_ns_url(); uuid_ns_url
--------------------------------------6ba7b811-9dad-11d1-80b4-00c04fd430c8
(1 row)
test=# select uuid_ns_oid(); uuid_ns_oid
--------------------------------------6ba7b812-9dad-11d1-80b4-00c04fd430c8
(1 row)
test=# select uuid_ns_x500(); uuid_ns_x500
--------------------------------------6ba7b814-9dad-11d1-80b4-00c04fd430c8
(1 row)
test=# select uuid_make_v1(); uuid_make_v1
--------------------------------------ca06523c-e826-11db-8418-001aa008dc89
(1 row)
test=# select uuid_make_v1mc(); uuid_make_v1mc
--------------------------------------cb9df960-e826-11db-bbd1-03614e7a3ea6
(1 row)
test=# select uuid_make_v3(uuid_ns_url(), 'http://www.postgresql.org'); uuid_make_v3
--------------------------------------cf16fe52-3365-3a1f-8572-288d8d2aaa46
(1 row)
test=# select uuid_make_v4(); uuid_make_v4
--------------------------------------ca16279c-f15d-4a33-a066-b657b338ccd8
(1 row)
test=# select uuid_make_v5(uuid_ns_url(), 'http://www.postgresql.org'); uuid_make_v5
--------------------------------------e1ee1ad4-cd4e-5889-962a-4f605a68d94e
(1 row)
--
Peter Eisentraut
http://developer.postgresql.org/~petere/