1
|
--
|
2
|
-- PostgreSQL database dump
|
3
|
--
|
4
|
|
5
|
SET statement_timeout = 0;
|
6
|
SET client_encoding = 'UTF8';
|
7
|
SET standard_conforming_strings = off;
|
8
|
SET check_function_bodies = false;
|
9
|
SET client_min_messages = warning;
|
10
|
SET escape_string_warning = off;
|
11
|
|
12
|
--
|
13
|
-- Name: functions; Type: SCHEMA; Schema: -; Owner: -
|
14
|
--
|
15
|
|
16
|
CREATE SCHEMA functions;
|
17
|
|
18
|
|
19
|
SET search_path = functions, pg_catalog;
|
20
|
|
21
|
--
|
22
|
-- Name: _alt(); Type: FUNCTION; Schema: functions; Owner: -
|
23
|
--
|
24
|
|
25
|
CREATE FUNCTION _alt() RETURNS trigger
|
26
|
LANGUAGE plpgsql IMMUTABLE
|
27
|
AS $$
|
28
|
BEGIN
|
29
|
new.result := coalesce(new."0", new."1", new."2", new."3", new."4", new."5",
|
30
|
new."6", new."7", new."8", new."9");
|
31
|
RETURN new;
|
32
|
END;
|
33
|
$$;
|
34
|
|
35
|
|
36
|
--
|
37
|
-- Name: _merge(); Type: FUNCTION; Schema: functions; Owner: -
|
38
|
--
|
39
|
|
40
|
CREATE FUNCTION _merge() RETURNS trigger
|
41
|
LANGUAGE plpgsql IMMUTABLE
|
42
|
AS $$
|
43
|
BEGIN
|
44
|
new.result := (
|
45
|
SELECT functions.join_strs('; ', value)
|
46
|
FROM
|
47
|
(
|
48
|
SELECT *
|
49
|
FROM
|
50
|
(
|
51
|
SELECT
|
52
|
DISTINCT ON (value)
|
53
|
*
|
54
|
FROM
|
55
|
(VALUES
|
56
|
(0, new."0")
|
57
|
, (1, new."1")
|
58
|
, (2, new."2")
|
59
|
, (3, new."3")
|
60
|
, (4, new."4")
|
61
|
, (5, new."5")
|
62
|
, (6, new."6")
|
63
|
, (7, new."7")
|
64
|
, (8, new."8")
|
65
|
, (9, new."9")
|
66
|
)
|
67
|
AS v (sort_order, value)
|
68
|
)
|
69
|
AS v
|
70
|
ORDER BY sort_order
|
71
|
)
|
72
|
AS v
|
73
|
);
|
74
|
RETURN new;
|
75
|
END;
|
76
|
$$;
|
77
|
|
78
|
|
79
|
--
|
80
|
-- Name: boolean(text); Type: FUNCTION; Schema: functions; Owner: -
|
81
|
--
|
82
|
|
83
|
CREATE FUNCTION "boolean"(value text) RETURNS boolean
|
84
|
LANGUAGE plpgsql IMMUTABLE STRICT
|
85
|
AS $$
|
86
|
BEGIN
|
87
|
BEGIN
|
88
|
RETURN value::boolean;
|
89
|
EXCEPTION
|
90
|
WHEN data_exception THEN
|
91
|
RAISE WARNING '%', SQLERRM;
|
92
|
RETURN NULL;
|
93
|
END;
|
94
|
RETURN new;
|
95
|
END;
|
96
|
$$;
|
97
|
|
98
|
|
99
|
--
|
100
|
-- Name: double precision(text); Type: FUNCTION; Schema: functions; Owner: -
|
101
|
--
|
102
|
|
103
|
CREATE FUNCTION "double precision"(value text) RETURNS double precision
|
104
|
LANGUAGE plpgsql IMMUTABLE STRICT
|
105
|
AS $$
|
106
|
BEGIN
|
107
|
BEGIN
|
108
|
RETURN value::double precision;
|
109
|
EXCEPTION
|
110
|
WHEN data_exception THEN
|
111
|
RAISE WARNING '%', SQLERRM;
|
112
|
RETURN NULL;
|
113
|
END;
|
114
|
RETURN new;
|
115
|
END;
|
116
|
$$;
|
117
|
|
118
|
|
119
|
--
|
120
|
-- Name: ensure_not_null(text); Type: FUNCTION; Schema: functions; Owner: -
|
121
|
--
|
122
|
|
123
|
CREATE FUNCTION ensure_not_null(value text) RETURNS text
|
124
|
LANGUAGE sql IMMUTABLE
|
125
|
AS $_$
|
126
|
SELECT COALESCE($1, E'\\N');
|
127
|
$_$;
|
128
|
|
129
|
|
130
|
--
|
131
|
-- Name: join_strs_(text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
132
|
--
|
133
|
|
134
|
CREATE FUNCTION join_strs_(state text, delim text, value text) RETURNS text
|
135
|
LANGUAGE sql IMMUTABLE
|
136
|
AS $_$
|
137
|
SELECT $1 || (CASE
|
138
|
WHEN $1 = '' OR $3 IS NULL OR $3 = ''
|
139
|
THEN ''
|
140
|
ELSE $2
|
141
|
END) || coalesce($3, '');
|
142
|
$_$;
|
143
|
|
144
|
|
145
|
--
|
146
|
-- Name: timestamp with time zone(text); Type: FUNCTION; Schema: functions; Owner: -
|
147
|
--
|
148
|
|
149
|
CREATE FUNCTION "timestamp with time zone"(value text) RETURNS timestamp with time zone
|
150
|
LANGUAGE plpgsql IMMUTABLE STRICT
|
151
|
AS $$
|
152
|
BEGIN
|
153
|
BEGIN
|
154
|
RETURN value::timestamp with time zone;
|
155
|
EXCEPTION
|
156
|
WHEN data_exception THEN
|
157
|
RAISE WARNING '%', SQLERRM;
|
158
|
RETURN NULL;
|
159
|
END;
|
160
|
RETURN new;
|
161
|
END;
|
162
|
$$;
|
163
|
|
164
|
|
165
|
--
|
166
|
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: -
|
167
|
--
|
168
|
|
169
|
CREATE AGGREGATE join_strs(text, text) (
|
170
|
SFUNC = join_strs_,
|
171
|
STYPE = text,
|
172
|
INITCOND = ''
|
173
|
);
|
174
|
|
175
|
|
176
|
SET default_tablespace = '';
|
177
|
|
178
|
SET default_with_oids = false;
|
179
|
|
180
|
--
|
181
|
-- Name: _alt; Type: TABLE; Schema: functions; Owner: -; Tablespace:
|
182
|
--
|
183
|
|
184
|
CREATE TABLE _alt (
|
185
|
result text,
|
186
|
not_null_col boolean DEFAULT true NOT NULL,
|
187
|
"0" text,
|
188
|
"1" text,
|
189
|
"2" text,
|
190
|
"3" text,
|
191
|
"4" text,
|
192
|
"5" text,
|
193
|
"6" text,
|
194
|
"7" text,
|
195
|
"8" text,
|
196
|
"9" text
|
197
|
);
|
198
|
|
199
|
|
200
|
--
|
201
|
-- Name: _merge; Type: TABLE; Schema: functions; Owner: -; Tablespace:
|
202
|
--
|
203
|
|
204
|
CREATE TABLE _merge (
|
205
|
result text,
|
206
|
not_null_col boolean DEFAULT true NOT NULL,
|
207
|
"0" text,
|
208
|
"1" text,
|
209
|
"2" text,
|
210
|
"3" text,
|
211
|
"4" text,
|
212
|
"5" text,
|
213
|
"6" text,
|
214
|
"7" text,
|
215
|
"8" text,
|
216
|
"9" text
|
217
|
);
|
218
|
|
219
|
|
220
|
--
|
221
|
-- Name: _alt_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
222
|
--
|
223
|
|
224
|
CREATE UNIQUE INDEX _alt_unique ON _alt USING btree (ensure_not_null("0"), ensure_not_null("1"), ensure_not_null("2"), ensure_not_null("3"), ensure_not_null("4"), ensure_not_null("5"), ensure_not_null("6"), ensure_not_null("7"), ensure_not_null("8"), ensure_not_null("9"));
|
225
|
|
226
|
|
227
|
--
|
228
|
-- Name: _merge_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
229
|
--
|
230
|
|
231
|
CREATE UNIQUE INDEX _merge_unique ON _merge USING btree (ensure_not_null("0"), ensure_not_null("1"), ensure_not_null("2"), ensure_not_null("3"), ensure_not_null("4"), ensure_not_null("5"), ensure_not_null("6"), ensure_not_null("7"), ensure_not_null("8"), ensure_not_null("9"));
|
232
|
|
233
|
|
234
|
--
|
235
|
-- Name: _alt; Type: TRIGGER; Schema: functions; Owner: -
|
236
|
--
|
237
|
|
238
|
CREATE TRIGGER _alt BEFORE INSERT OR UPDATE ON _alt FOR EACH ROW EXECUTE PROCEDURE _alt();
|
239
|
|
240
|
|
241
|
--
|
242
|
-- Name: _merge; Type: TRIGGER; Schema: functions; Owner: -
|
243
|
--
|
244
|
|
245
|
CREATE TRIGGER _merge BEFORE INSERT OR UPDATE ON _merge FOR EACH ROW EXECUTE PROCEDURE _merge();
|
246
|
|
247
|
|
248
|
--
|
249
|
-- PostgreSQL database dump complete
|
250
|
--
|
251
|
|