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: datatype; Type: TYPE; Schema: functions; Owner: -
|
23
|
--
|
24
|
|
25
|
CREATE TYPE datatype AS ENUM (
|
26
|
'str',
|
27
|
'float'
|
28
|
);
|
29
|
|
30
|
|
31
|
--
|
32
|
-- Name: _alt(); Type: FUNCTION; Schema: functions; Owner: -
|
33
|
--
|
34
|
|
35
|
CREATE FUNCTION _alt() RETURNS trigger
|
36
|
LANGUAGE plpgsql IMMUTABLE
|
37
|
AS $$
|
38
|
BEGIN
|
39
|
new.result := _alt(new."0", new."1", new."2", new."3", new."4", new."5",
|
40
|
new."6", new."7", new."8", new."9");
|
41
|
RETURN new;
|
42
|
END;
|
43
|
$$;
|
44
|
|
45
|
|
46
|
--
|
47
|
-- Name: _alt(text, text, text, text, text, text, text, text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
48
|
--
|
49
|
|
50
|
CREATE FUNCTION _alt("0" text DEFAULT NULL::text, "1" text DEFAULT NULL::text, "2" text DEFAULT NULL::text, "3" text DEFAULT NULL::text, "4" text DEFAULT NULL::text, "5" text DEFAULT NULL::text, "6" text DEFAULT NULL::text, "7" text DEFAULT NULL::text, "8" text DEFAULT NULL::text, "9" text DEFAULT NULL::text) RETURNS text
|
51
|
LANGUAGE sql IMMUTABLE
|
52
|
AS $_$
|
53
|
SELECT coalesce($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
54
|
$_$;
|
55
|
|
56
|
|
57
|
--
|
58
|
-- Name: _label(); Type: FUNCTION; Schema: functions; Owner: -
|
59
|
--
|
60
|
|
61
|
CREATE FUNCTION _label() RETURNS trigger
|
62
|
LANGUAGE plpgsql IMMUTABLE
|
63
|
AS $$
|
64
|
BEGIN
|
65
|
new.result := (SELECT new.label||': '||new.value);
|
66
|
RETURN new;
|
67
|
END;
|
68
|
$$;
|
69
|
|
70
|
|
71
|
--
|
72
|
-- Name: _merge(); Type: FUNCTION; Schema: functions; Owner: -
|
73
|
--
|
74
|
|
75
|
CREATE FUNCTION _merge() RETURNS trigger
|
76
|
LANGUAGE plpgsql IMMUTABLE
|
77
|
AS $$
|
78
|
BEGIN
|
79
|
new.result := _merge(new."0", new."1", new."2", new."3", new."4", new."5",
|
80
|
new."6", new."7", new."8", new."9");
|
81
|
RETURN new;
|
82
|
END;
|
83
|
$$;
|
84
|
|
85
|
|
86
|
--
|
87
|
-- Name: _merge(text, text, text, text, text, text, text, text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
88
|
--
|
89
|
|
90
|
CREATE FUNCTION _merge("0" text DEFAULT NULL::text, "1" text DEFAULT NULL::text, "2" text DEFAULT NULL::text, "3" text DEFAULT NULL::text, "4" text DEFAULT NULL::text, "5" text DEFAULT NULL::text, "6" text DEFAULT NULL::text, "7" text DEFAULT NULL::text, "8" text DEFAULT NULL::text, "9" text DEFAULT NULL::text) RETURNS text
|
91
|
LANGUAGE sql IMMUTABLE
|
92
|
AS $_$
|
93
|
SELECT functions.join_strs('; ', value)
|
94
|
FROM
|
95
|
(
|
96
|
SELECT *
|
97
|
FROM
|
98
|
(
|
99
|
SELECT
|
100
|
DISTINCT ON (value)
|
101
|
*
|
102
|
FROM
|
103
|
(VALUES
|
104
|
(0, $1)
|
105
|
, (1, $2)
|
106
|
, (2, $3)
|
107
|
, (3, $4)
|
108
|
, (4, $5)
|
109
|
, (5, $6)
|
110
|
, (6, $7)
|
111
|
, (7, $8)
|
112
|
, (8, $9)
|
113
|
, (9, $10)
|
114
|
)
|
115
|
AS v (sort_order, value)
|
116
|
)
|
117
|
AS v
|
118
|
ORDER BY sort_order
|
119
|
)
|
120
|
AS v
|
121
|
$_$;
|
122
|
|
123
|
|
124
|
--
|
125
|
-- Name: _nullIf(); Type: FUNCTION; Schema: functions; Owner: -
|
126
|
--
|
127
|
|
128
|
CREATE FUNCTION "_nullIf"() RETURNS trigger
|
129
|
LANGUAGE plpgsql IMMUTABLE
|
130
|
AS $$
|
131
|
BEGIN
|
132
|
IF new.type = 'str' THEN -- no cast needed
|
133
|
new.result := (SELECT nullif(new.value, new."null"));
|
134
|
-- Invalid value is ignored, but invalid null value generates error
|
135
|
ELSIF new.type = 'float' THEN
|
136
|
DECLARE
|
137
|
-- Outside the try block so that invalid null value generates error
|
138
|
"null" double precision := new."null"::double precision;
|
139
|
BEGIN
|
140
|
new.result := (SELECT nullif(new.value::double precision, "null"));
|
141
|
EXCEPTION
|
142
|
WHEN data_exception THEN NULL; -- ignore invalid value
|
143
|
END;
|
144
|
END IF;
|
145
|
|
146
|
RETURN new;
|
147
|
END;
|
148
|
$$;
|
149
|
|
150
|
|
151
|
--
|
152
|
-- Name: join_strs_(text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
153
|
--
|
154
|
|
155
|
CREATE FUNCTION join_strs_(state text, delim text, value text) RETURNS text
|
156
|
LANGUAGE sql IMMUTABLE
|
157
|
AS $_$
|
158
|
SELECT $1 || (CASE
|
159
|
WHEN $1 = '' OR $3 IS NULL OR $3 = ''
|
160
|
THEN ''
|
161
|
ELSE $2
|
162
|
END) || coalesce($3, '');
|
163
|
$_$;
|
164
|
|
165
|
|
166
|
--
|
167
|
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: -
|
168
|
--
|
169
|
|
170
|
CREATE AGGREGATE join_strs(text, text) (
|
171
|
SFUNC = join_strs_,
|
172
|
STYPE = text,
|
173
|
INITCOND = ''
|
174
|
);
|
175
|
|
176
|
|
177
|
SET default_tablespace = '';
|
178
|
|
179
|
SET default_with_oids = false;
|
180
|
|
181
|
--
|
182
|
-- Name: _alt; Type: TABLE; Schema: functions; Owner: -; Tablespace:
|
183
|
--
|
184
|
|
185
|
CREATE TABLE _alt (
|
186
|
result text,
|
187
|
not_null_col boolean DEFAULT true NOT NULL,
|
188
|
"0" text,
|
189
|
"1" text,
|
190
|
"2" text,
|
191
|
"3" text,
|
192
|
"4" text,
|
193
|
"5" text,
|
194
|
"6" text,
|
195
|
"7" text,
|
196
|
"8" text,
|
197
|
"9" text
|
198
|
);
|
199
|
|
200
|
|
201
|
--
|
202
|
-- Name: _label; Type: TABLE; Schema: functions; Owner: -; Tablespace:
|
203
|
--
|
204
|
|
205
|
CREATE TABLE _label (
|
206
|
result text,
|
207
|
not_null_col boolean DEFAULT true NOT NULL,
|
208
|
label text NOT NULL,
|
209
|
value text
|
210
|
);
|
211
|
|
212
|
|
213
|
--
|
214
|
-- Name: _merge; Type: TABLE; Schema: functions; Owner: -; Tablespace:
|
215
|
--
|
216
|
|
217
|
CREATE TABLE _merge (
|
218
|
result text,
|
219
|
not_null_col boolean DEFAULT true NOT NULL,
|
220
|
"0" text,
|
221
|
"1" text,
|
222
|
"2" text,
|
223
|
"3" text,
|
224
|
"4" text,
|
225
|
"5" text,
|
226
|
"6" text,
|
227
|
"7" text,
|
228
|
"8" text,
|
229
|
"9" text
|
230
|
);
|
231
|
|
232
|
|
233
|
--
|
234
|
-- Name: _nullIf; Type: TABLE; Schema: functions; Owner: -; Tablespace:
|
235
|
--
|
236
|
|
237
|
CREATE TABLE "_nullIf" (
|
238
|
result text,
|
239
|
not_null_col boolean DEFAULT true NOT NULL,
|
240
|
"null" text NOT NULL,
|
241
|
type datatype DEFAULT 'str'::datatype NOT NULL,
|
242
|
value text
|
243
|
);
|
244
|
|
245
|
|
246
|
--
|
247
|
-- Name: _alt_0; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
248
|
--
|
249
|
|
250
|
CREATE INDEX _alt_0 ON _alt USING btree ((COALESCE("0", '\\N'::text)));
|
251
|
|
252
|
|
253
|
--
|
254
|
-- Name: _alt_1; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
255
|
--
|
256
|
|
257
|
CREATE INDEX _alt_1 ON _alt USING btree ((COALESCE("1", '\\N'::text)));
|
258
|
|
259
|
|
260
|
--
|
261
|
-- Name: _alt_2; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
262
|
--
|
263
|
|
264
|
CREATE INDEX _alt_2 ON _alt USING btree ((COALESCE("2", '\\N'::text)));
|
265
|
|
266
|
|
267
|
--
|
268
|
-- Name: _alt_3; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
269
|
--
|
270
|
|
271
|
CREATE INDEX _alt_3 ON _alt USING btree ((COALESCE("3", '\\N'::text)));
|
272
|
|
273
|
|
274
|
--
|
275
|
-- Name: _alt_4; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
276
|
--
|
277
|
|
278
|
CREATE INDEX _alt_4 ON _alt USING btree ((COALESCE("4", '\\N'::text)));
|
279
|
|
280
|
|
281
|
--
|
282
|
-- Name: _alt_5; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
283
|
--
|
284
|
|
285
|
CREATE INDEX _alt_5 ON _alt USING btree ((COALESCE("5", '\\N'::text)));
|
286
|
|
287
|
|
288
|
--
|
289
|
-- Name: _alt_6; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
290
|
--
|
291
|
|
292
|
CREATE INDEX _alt_6 ON _alt USING btree ((COALESCE("6", '\\N'::text)));
|
293
|
|
294
|
|
295
|
--
|
296
|
-- Name: _alt_7; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
297
|
--
|
298
|
|
299
|
CREATE INDEX _alt_7 ON _alt USING btree ((COALESCE("7", '\\N'::text)));
|
300
|
|
301
|
|
302
|
--
|
303
|
-- Name: _alt_8; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
304
|
--
|
305
|
|
306
|
CREATE INDEX _alt_8 ON _alt USING btree ((COALESCE("8", '\\N'::text)));
|
307
|
|
308
|
|
309
|
--
|
310
|
-- Name: _alt_9; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
311
|
--
|
312
|
|
313
|
CREATE INDEX _alt_9 ON _alt USING btree ((COALESCE("9", '\\N'::text)));
|
314
|
|
315
|
|
316
|
--
|
317
|
-- Name: _alt_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
318
|
--
|
319
|
|
320
|
CREATE UNIQUE INDEX _alt_unique ON _alt USING btree ((COALESCE("0", '\\N'::text)), (COALESCE("1", '\\N'::text)), (COALESCE("2", '\\N'::text)), (COALESCE("3", '\\N'::text)), (COALESCE("4", '\\N'::text)), (COALESCE("5", '\\N'::text)), (COALESCE("6", '\\N'::text)), (COALESCE("7", '\\N'::text)), (COALESCE("8", '\\N'::text)), (COALESCE("9", '\\N'::text)));
|
321
|
|
322
|
|
323
|
--
|
324
|
-- Name: _label_label; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
325
|
--
|
326
|
|
327
|
CREATE INDEX _label_label ON _label USING btree ((COALESCE(label, '\\N'::text)));
|
328
|
|
329
|
|
330
|
--
|
331
|
-- Name: _label_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
332
|
--
|
333
|
|
334
|
CREATE UNIQUE INDEX _label_unique ON _label USING btree ((COALESCE(label, '\\N'::text)), (COALESCE(value, '\\N'::text)));
|
335
|
|
336
|
|
337
|
--
|
338
|
-- Name: _label_value; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
339
|
--
|
340
|
|
341
|
CREATE INDEX _label_value ON _label USING btree (value);
|
342
|
|
343
|
|
344
|
--
|
345
|
-- Name: _merge_0; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
346
|
--
|
347
|
|
348
|
CREATE INDEX _merge_0 ON _merge USING btree ((COALESCE("0", '\\N'::text)));
|
349
|
|
350
|
|
351
|
--
|
352
|
-- Name: _merge_1; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
353
|
--
|
354
|
|
355
|
CREATE INDEX _merge_1 ON _merge USING btree ((COALESCE("1", '\\N'::text)));
|
356
|
|
357
|
|
358
|
--
|
359
|
-- Name: _merge_2; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
360
|
--
|
361
|
|
362
|
CREATE INDEX _merge_2 ON _merge USING btree ((COALESCE("2", '\\N'::text)));
|
363
|
|
364
|
|
365
|
--
|
366
|
-- Name: _merge_3; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
367
|
--
|
368
|
|
369
|
CREATE INDEX _merge_3 ON _merge USING btree ((COALESCE("3", '\\N'::text)));
|
370
|
|
371
|
|
372
|
--
|
373
|
-- Name: _merge_4; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
374
|
--
|
375
|
|
376
|
CREATE INDEX _merge_4 ON _merge USING btree ((COALESCE("4", '\\N'::text)));
|
377
|
|
378
|
|
379
|
--
|
380
|
-- Name: _merge_5; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
381
|
--
|
382
|
|
383
|
CREATE INDEX _merge_5 ON _merge USING btree ((COALESCE("5", '\\N'::text)));
|
384
|
|
385
|
|
386
|
--
|
387
|
-- Name: _merge_6; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
388
|
--
|
389
|
|
390
|
CREATE INDEX _merge_6 ON _merge USING btree ((COALESCE("6", '\\N'::text)));
|
391
|
|
392
|
|
393
|
--
|
394
|
-- Name: _merge_7; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
395
|
--
|
396
|
|
397
|
CREATE INDEX _merge_7 ON _merge USING btree ((COALESCE("7", '\\N'::text)));
|
398
|
|
399
|
|
400
|
--
|
401
|
-- Name: _merge_8; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
402
|
--
|
403
|
|
404
|
CREATE INDEX _merge_8 ON _merge USING btree ((COALESCE("8", '\\N'::text)));
|
405
|
|
406
|
|
407
|
--
|
408
|
-- Name: _merge_9; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
409
|
--
|
410
|
|
411
|
CREATE INDEX _merge_9 ON _merge USING btree ((COALESCE("9", '\\N'::text)));
|
412
|
|
413
|
|
414
|
--
|
415
|
-- Name: _merge_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
416
|
--
|
417
|
|
418
|
CREATE UNIQUE INDEX _merge_unique ON _merge USING btree ((COALESCE("0", '\\N'::text)), (COALESCE("1", '\\N'::text)), (COALESCE("2", '\\N'::text)), (COALESCE("3", '\\N'::text)), (COALESCE("4", '\\N'::text)), (COALESCE("5", '\\N'::text)), (COALESCE("6", '\\N'::text)), (COALESCE("7", '\\N'::text)), (COALESCE("8", '\\N'::text)), (COALESCE("9", '\\N'::text)));
|
419
|
|
420
|
|
421
|
--
|
422
|
-- Name: _nullIf_null; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
423
|
--
|
424
|
|
425
|
CREATE INDEX "_nullIf_null" ON "_nullIf" USING btree ("null");
|
426
|
|
427
|
|
428
|
--
|
429
|
-- Name: _nullIf_type; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
430
|
--
|
431
|
|
432
|
CREATE INDEX "_nullIf_type" ON "_nullIf" USING btree (type);
|
433
|
|
434
|
|
435
|
--
|
436
|
-- Name: _nullIf_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
437
|
--
|
438
|
|
439
|
CREATE UNIQUE INDEX "_nullIf_unique" ON "_nullIf" USING btree ("null", type, (COALESCE(value, '\\N'::text)));
|
440
|
|
441
|
|
442
|
--
|
443
|
-- Name: _nullIf_value; Type: INDEX; Schema: functions; Owner: -; Tablespace:
|
444
|
--
|
445
|
|
446
|
CREATE INDEX "_nullIf_value" ON "_nullIf" USING btree (value);
|
447
|
|
448
|
|
449
|
--
|
450
|
-- Name: _alt; Type: TRIGGER; Schema: functions; Owner: -
|
451
|
--
|
452
|
|
453
|
CREATE TRIGGER _alt BEFORE INSERT OR UPDATE ON _alt FOR EACH ROW EXECUTE PROCEDURE functions._alt();
|
454
|
|
455
|
|
456
|
--
|
457
|
-- Name: _label; Type: TRIGGER; Schema: functions; Owner: -
|
458
|
--
|
459
|
|
460
|
CREATE TRIGGER _label BEFORE INSERT OR UPDATE ON _label FOR EACH ROW EXECUTE PROCEDURE _label();
|
461
|
|
462
|
|
463
|
--
|
464
|
-- Name: _merge; Type: TRIGGER; Schema: functions; Owner: -
|
465
|
--
|
466
|
|
467
|
CREATE TRIGGER _merge BEFORE INSERT OR UPDATE ON _merge FOR EACH ROW EXECUTE PROCEDURE functions._merge();
|
468
|
|
469
|
|
470
|
--
|
471
|
-- Name: _nullIf; Type: TRIGGER; Schema: functions; Owner: -
|
472
|
--
|
473
|
|
474
|
CREATE TRIGGER "_nullIf" BEFORE INSERT OR UPDATE ON "_nullIf" FOR EACH ROW EXECUTE PROCEDURE "_nullIf"();
|
475
|
|
476
|
|
477
|
--
|
478
|
-- PostgreSQL database dump complete
|
479
|
--
|
480
|
|