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 The 'make install' step will need sufficient privileges to write
34 to the Postgres extension directory, so 'sudo make install'
37 Installation can be done via the usual Postgres extension mechanism.
38 create extension pduuid;
40 The extension is re-locatable, so you can specify a schema if you
43 Installation can be done manually with:
46 psql -f uninstall-uuid.sql
48 A pure postgres implementation is also supplied of just the generation
49 functions in purepguuid.sql, though this is very inefficient, feature
50 incomplete, and untested. It's there if you need it though.
55 returns a version 1 uuid. if the mac address can't be determined,
59 returns a version 1 uuid using a random mac address
62 returns a version 3 uuid using the supplied namespace uuid and the
63 given input string. This is an md5 based uuid.
66 returns a version 4 uuid. This is a random uuid. The odds of collision
67 are vanishingly low and it is safe to use for regular production uuid
71 returns a version 5 uuid using the supplied namespace uuid and the
72 given input string. This is an sha1 based uuid.
75 Returns a version 5 uuid using the URL namespace.
78 Returns a version 5 uuid using the DNS namespace.
81 Returns a version 5 uuid using the DNS namespace.
84 Returns a version 5 uuid using the DNS namespace.
86 UUID Lookup Functions:
89 returns the most recent uuid generated by this backend. Returns
90 the nil uuid if no uuids have been generated yet.
93 Returns the nil uuid (all bits zero).
96 Returns the DNS namespace uuid.
97 6ba7b810-9dad-11d1-80b4-00c04fd430c8
100 Returns the URL namespace uuid.
101 6ba7b811-9dad-11d1-80b4-00c04fd430c8
104 Returns the OID namespace uuid.
105 6ba7b812-9dad-11d1-80b4-00c04fd430c8
108 Returns the X500 namespace uuid.
109 6ba7b813-9dad-11d1-80b4-00c04fd430c8
113 Cast functions and casts are created for uuids to and from data types
114 where this is reasonable:
116 Bytea: treats the UUID as an array of bytes. This is always in
117 network byte order for the subfields of a uuid, where applicable.
119 Numeric: treats the UUID as a 128 bit number and converts it to a numeric.
121 Bit(128) and bit varying: treats the uuid as a 128 bit vector.
122 Casts to bit(n) where n is shorter than 128 will truncate
123 the uuid. Where n is longer than 128, the bit vector
124 will be zero extended.
126 Field extraction functions:
129 Returns an integer corresponding to the 4 bit version number.
132 Returns a macaddr type corresponding to the mac address part of the
133 uuid. This function can be called on any uuid, not just version 1 uuids.
136 Returns a timestamp corresponding to the timestamp field in the uuid. You
137 probably want to use uuid_timestamptz().
139 uuid_timestamptz(uuid)
140 Returns a timestamp with time zonecorresponding to the timestamp field in the