]> pd.if.org Git - uuid/blob - postgres/README
bbf7694a78ddaaae5edee2e59158dcb6ccb387d1
[uuid] / postgres / README
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.
6
7 Credit: the hash functions are stripped down implementations from
8 libtomcrypt by Tom St Denis, also in the public domain.
9
10 Functions supplied are uuid generation functions, conforming (with
11 one exception) to RFC 4122 (see below for details).
12
13 Features:
14
15 UUID generation functions for version 1, 3, 4, and 5 uuids.
16
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).
21
22 No external library dependency (other than the standard C library).
23 The uuid generation has been written from scratch and is included
24 with the source.
25
26 The entire package is in the public domain, so there are no licensing
27 issues.
28
29 Compiles with the usual postgres addon infrastructure.
30 make
31 make install
32
33 Installation can be done manually with:
34
35 psql -f uuid.sql
36 psql -f uninstall-uuid.sql
37
38 Or as a postgres extension:
39 create extension pduuid;
40
41 A pure postgres implementation is also supplied of just the generation
42 functions in purepguuid.sql.
43
44 Generation Functions:
45
46 uuid_v1()
47 returns a version 1 uuid.  if the mac address can't be determined,
48 uses a random one.
49
50 uuid_v1mc()
51 returns a version 1 uuid using a random mac address
52
53 uuid_v3(uuid, text)
54 returns a version 3 uuid using the supplied namespace uuid and the
55 given input string.  This is an md5 based uuid.
56
57 uuid_v4()
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
60 generation.
61
62 uuid_v5(uuid, text)
63 returns a version 5 uuid using the supplied namespace uuid and the
64 given input string.  This is an sha1 based uuid.
65
66 uuid_url(text)
67 Returns a version 5 uuid using the URL namespace.
68
69 uuid_dns(text)
70 Returns a version 5 uuid using the DNS namespace.
71
72 uuid_oid(text)
73 Returns a version 5 uuid using the DNS namespace.
74
75 uuid_x500(text)
76 Returns a version 5 uuid using the DNS namespace.
77
78 UUID Lookup Functions:
79
80 uuid_recent()
81 returns the most recent uuid generated by this backend.  Returns
82 the nil uuid if no uuids have been generated yet.
83
84 uuid_nil()
85 Returns the nil uuid (all bits zero).
86
87 uuid_ns_dns()
88 Returns the DNS namespace uuid.
89 6ba7b810-9dad-11d1-80b4-00c04fd430c8
90
91 uuid_ns_url()
92 Returns the URL namespace uuid.
93 6ba7b811-9dad-11d1-80b4-00c04fd430c8
94
95 uuid_ns_oid()
96 Returns the OID namespace uuid.
97 6ba7b812-9dad-11d1-80b4-00c04fd430c8
98
99 uuid_ns_x500()
100 Returns the X500 namespace uuid.
101 6ba7b813-9dad-11d1-80b4-00c04fd430c8
102
103 Casting Support:
104
105 Cast functions and casts are created for uuids to and from data types
106 where this is reasonable:
107
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.
110
111 Numeric: treats the UUID as a 128 bit number and converts it to a numeric.
112
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.
117
118 Field extraction functions:
119
120 uuid_version(uuid)
121 Returns an integer corresponding to the 4 bit version number.
122
123 uuid_macaddr(uuid)
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.
126
127 uuid_timestamp(uuid)
128 Returns a timestamp corresponding to the timestamp field in the uuid.  You
129 probably want to use uuid_timestamptz().
130
131 uuid_timestamptz(uuid)
132 Returns a timestamp with time zonecorresponding to the timestamp field in the
133 uuid.