1 This software package is an addon module for postgres. It supplies
2 support functions for the built-in uuid data type. It was originally built and
3 tested against postgres version 8.4.0. This file and all supplied files
4 are written by Nathan Wagner and placed in the public domain. Bug
5 reports to nw@hydaspes.if.org.
7 Credit: the hash functions are stripped down implementations from
8 libtomcrypt by Tom St Denis, also in the public domain.
10 Functions supplied are uuid generation functions, conforming (with
11 one exception) to RFC 4122 (see below for details).
15 UUID generation functions for version 1, 3, 4, and 5 uuids.
17 RFC 4122 compliance, with the exception of the multicast bit
18 for randomly generated mac addresses. This module sets the correct
19 bit (the most significant bit), rather than the one specified in the RFC
20 (the least significant one).
22 No external library dependency (other than the standard C library).
23 The uuid generation has been written from scratch and is included
26 The entire package is in the public domain, so there are no licensing
29 Compiles with the usual postgres addon infrastructure.
33 Installation can be done manually with:
36 psql -f uninstall-uuid.sql
38 Or as a postgres extension:
39 create extension pduuid;
41 A pure postgres implementation is also supplied of just the generation
42 functions in purepguuid.sql.
47 returns a version 1 uuid. if the mac address can't be determined,
51 returns a version 1 uuid using a random mac address
54 returns a version 3 uuid using the supplied namespace uuid and the
55 given input string. This is an md5 based uuid.
58 returns a version 4 uuid. This is a random uuid. The odds of collision
59 are vanishingly low and it is safe to use for regular production uuid
63 returns a version 5 uuid using the supplied namespace uuid and the
64 given input string. This is an sha1 based uuid.
67 Returns a version 5 uuid using the URL namespace.
70 Returns a version 5 uuid using the DNS namespace.
73 Returns a version 5 uuid using the DNS namespace.
76 Returns a version 5 uuid using the DNS namespace.
78 UUID Lookup Functions:
81 returns the most recent uuid generated by this backend. Returns
82 the nil uuid if no uuids have been generated yet.
85 Returns the nil uuid (all bits zero).
88 Returns the DNS namespace uuid.
89 6ba7b810-9dad-11d1-80b4-00c04fd430c8
92 Returns the URL namespace uuid.
93 6ba7b811-9dad-11d1-80b4-00c04fd430c8
96 Returns the OID namespace uuid.
97 6ba7b812-9dad-11d1-80b4-00c04fd430c8
100 Returns the X500 namespace uuid.
101 6ba7b813-9dad-11d1-80b4-00c04fd430c8
105 Cast functions and casts are created for uuids to and from data types
106 where this is reasonable:
108 Bytea: treats the UUID as an array of bytes. This is always in
109 network byte order for the subfields of a uuid, where applicable.
111 Numeric: treats the UUID as a 128 bit number and converts it to a numeric.
113 Bit(128) and bit varying: treats the uuid as a 128 bit vector.
114 Casts to bit(n) where n is shorter than 128 will truncate
115 the uuid. Where n is longer than 128, the bit vector
116 will be zero extended.
118 Field extraction functions:
121 Returns an integer corresponding to the 4 bit version number.
124 Returns a macaddr type corresponding to the mac address part of the
125 uuid. This function can be called on any uuid, not just version 1 uuids.
128 Returns a timestamp corresponding to the timestamp field in the uuid. You
129 probably want to use uuid_timestamptz().
131 uuid_timestamptz(uuid)
132 Returns a timestamp with time zonecorresponding to the timestamp field in the