1 -- uuid support function install script
2 -- written by nathan wagner and placed in the public domain
4 create function uuid_v1() returns uuid as 'pduuid', 'uuid_gen_v1'
7 create function uuid_v1mc() returns uuid as 'pduuid', 'uuid_gen_v1_mc'
10 create function uuid_v3(uuid, text) returns uuid
11 as 'pduuid', 'uuid_gen_v3'
14 create function uuid_v4() returns uuid as 'pduuid', 'uuid_gen_v4'
17 create function uuid_v5(uuid, text) returns uuid
18 as 'pduuid', 'uuid_gen_v5'
21 create function uuid_recent() returns uuid as 'pduuid', 'uuid_recent'
24 create function uuid_nil() returns uuid as 'pduuid', 'uuid_nil'
27 create function uuid_ns_dns() returns uuid as 'pduuid', 'uuid_dns'
30 create function uuid_ns_oid() returns uuid as 'pduuid', 'uuid_oid'
33 create function uuid_ns_url() returns uuid as 'pduuid', 'uuid_url'
36 create function uuid_ns_x500() returns uuid as 'pduuid', 'uuid_x500'
39 create function uuid_url(text) returns uuid as $$
40 select uuid_v5(uuid_ns_url(), $1);
42 language 'sql' strict;
44 create function uuid_dns(text) returns uuid as $$
45 select uuid_v5(uuid_ns_dns(), $1);
47 language 'sql' strict;
49 create function uuid_oid(text) returns uuid as $$
50 select uuid_v5(uuid_ns_oid(), $1);
52 language 'sql' strict;
54 create function uuid_x500(text) returns uuid as $$
55 select uuid_v5(uuid_ns_x500(), $1);
57 language 'sql' strict;
63 create function uuid_bytea_cast(uuid) returns bytea as
64 'pduuid', 'uuid_cast_bytea'
67 create function uuid_bytea_uncast(bytea) returns uuid as
68 'pduuid', 'uuid_cast_from_bytea'
71 create cast (uuid as bytea) with function uuid_bytea_cast(uuid);
73 create cast (bytea as uuid) with function uuid_bytea_uncast(bytea);
77 create function uuid_numeric_cast(uuid) returns numeric as
78 'pduuid', 'uuid_cast_numeric'
81 create function uuid_numeric_uncast(numeric) returns uuid as
82 'pduuid', 'uuid_cast_from_numeric'
85 create cast (uuid as numeric) with function uuid_numeric_cast(uuid);
87 create cast (numeric as uuid) with function uuid_numeric_uncast(numeric);
89 -- Bit and bit varying
91 create function uuid_bit_cast(uuid) returns bit(128) as
92 'pduuid', 'uuid_cast_bit'
95 create function uuid_bit_uncast(bit(128)) returns uuid as
96 'pduuid', 'uuid_cast_from_bit'
99 create cast (uuid as bit(128)) with function uuid_bit_cast(uuid);
101 create cast (uuid as bit varying) with function uuid_bit_cast(uuid);
103 create cast (bit(128) as uuid) with function uuid_bit_uncast(bit(128));
105 create cast (bit varying as uuid) with function uuid_bit_uncast(bit(128));
107 -- Field extraction functions
109 create function uuid_version(uuid) returns integer as
110 'pduuid', 'uuid_extract_version'
113 create function uuid_macaddr(uuid) returns macaddr as
114 'pduuid', 'uuid_extract_macaddr'
117 create function uuid_timestamp(uuid) returns timestamp as
118 'pduuid', 'uuid_extract_timestamp'
121 create function uuid_timestamptz(uuid)
122 returns timestamp with time zone as
123 'pduuid', 'uuid_extract_timestamp'
127 -- cast to timestamp / extract timestamp
128 -- cast to macaddr / extract macaddr
130 -- extract clock sequence