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