]> pd.if.org Git - uuid/blob - postgres/pduuid--1.0.1.sql
mark functions as immutable
[uuid] / postgres / pduuid--1.0.1.sql
1 -- uuid support function install script
2 -- written by nathan wagner and placed in the public domain
3
4 create function uuid_v1() returns uuid as 'pduuid', 'uuid_gen_v1'
5 language C strict;
6
7 create function uuid_v1mc() returns uuid as 'pduuid', 'uuid_gen_v1_mc'
8 language C strict;
9
10 create function uuid_v3(uuid, text) returns uuid
11 as 'pduuid', 'uuid_gen_v3'
12 language C strict;
13
14 create function uuid_v4() returns uuid as 'pduuid', 'uuid_gen_v4'
15 language C strict;
16
17 create function uuid_v5(uuid, text) returns uuid
18 as 'pduuid', 'uuid_gen_v5'
19 language C strict;
20
21 create function uuid_recent() returns uuid as 'pduuid', 'uuid_recent'
22 language C strict;
23
24 create function uuid_nil() returns uuid as 'pduuid', 'uuid_nil'
25 language C immutable strict;
26
27 create function uuid_ns_dns() returns uuid as 'pduuid', 'uuid_dns'
28 language C immutable strict;
29
30 create function uuid_ns_oid() returns uuid as 'pduuid', 'uuid_oid'
31 language C immutable strict;
32
33 create function uuid_ns_url() returns uuid as 'pduuid', 'uuid_url'
34 language C immutable strict;
35
36 create function uuid_ns_x500() returns uuid as 'pduuid', 'uuid_x500'
37 language C immutable strict;
38
39 create function uuid_url(text) returns uuid as $$
40 select uuid_v5(uuid_ns_url(), $1);
41 $$
42 language 'sql' immutable strict;
43
44 create function uuid_dns(text) returns uuid as $$
45 select uuid_v5(uuid_ns_dns(), $1);
46 $$
47 language 'sql' immutable strict;
48
49 create function uuid_oid(text) returns uuid as $$
50 select uuid_v5(uuid_ns_oid(), $1);
51 $$
52 language 'sql' immutable strict;
53
54 create function uuid_x500(text) returns uuid as $$
55 select uuid_v5(uuid_ns_x500(), $1);
56 $$
57 language 'sql' immutable strict;
58
59 -- Casts
60
61 -- Bytea
62
63 create function uuid_bytea_cast(uuid) returns bytea as 
64 'pduuid', 'uuid_cast_bytea'
65 language C strict;
66
67 create function uuid_bytea_uncast(bytea) returns uuid as 
68 'pduuid', 'uuid_cast_from_bytea'
69 language C strict;
70
71 create cast (uuid as bytea) with function uuid_bytea_cast(uuid);
72
73 create cast (bytea as uuid) with function uuid_bytea_uncast(bytea);
74
75 -- Numeric
76
77 create function uuid_numeric_cast(uuid) returns numeric as 
78 'pduuid', 'uuid_cast_numeric'
79 language C strict;
80
81 create function uuid_numeric_uncast(numeric) returns uuid as 
82 'pduuid', 'uuid_cast_from_numeric'
83 language C strict;
84
85 create cast (uuid as numeric) with function uuid_numeric_cast(uuid);
86
87 create cast (numeric as uuid) with function uuid_numeric_uncast(numeric);
88
89 -- Bit and bit varying
90
91 create function uuid_bit_cast(uuid) returns bit(128) as 
92 'pduuid', 'uuid_cast_bit'
93 language C strict;
94
95 create function uuid_bit_uncast(bit(128)) returns uuid as 
96 'pduuid', 'uuid_cast_from_bit'
97 language C strict;
98
99 create cast (uuid as bit(128)) with function uuid_bit_cast(uuid);
100
101 create cast (uuid as bit varying) with function uuid_bit_cast(uuid);
102
103 create cast (bit(128) as uuid) with function uuid_bit_uncast(bit(128));
104
105 create cast (bit varying as uuid) with function uuid_bit_uncast(bit(128));
106
107 -- Field extraction functions
108
109 create function uuid_version(uuid) returns integer as
110 'pduuid', 'uuid_extract_version'
111 language C strict;
112
113 create function uuid_macaddr(uuid) returns macaddr as
114 'pduuid', 'uuid_extract_macaddr'
115 language C strict;
116
117 create function uuid_timestamp(uuid) returns timestamp as
118 'pduuid', 'uuid_extract_timestamp'
119 language C strict;
120
121 create function uuid_timestamptz(uuid)
122 returns timestamp with time zone as
123 'pduuid', 'uuid_extract_timestamp'
124 language C strict;
125
126 -- TODO
127 -- cast to timestamp / extract timestamp
128 -- cast to macaddr / extract macaddr
129 -- extract variant
130 -- extract clock sequence