Project

General

Profile

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 := coalesce(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: _label(); Type: FUNCTION; Schema: functions; Owner: -
48
--
49

    
50
CREATE FUNCTION _label() RETURNS trigger
51
    LANGUAGE plpgsql IMMUTABLE
52
    AS $$
53
BEGIN
54
    new.result := (SELECT new.label||': '||new.value);
55
    RETURN new;
56
END;
57
$$;
58

    
59

    
60
--
61
-- Name: _merge(); Type: FUNCTION; Schema: functions; Owner: -
62
--
63

    
64
CREATE FUNCTION _merge() RETURNS trigger
65
    LANGUAGE plpgsql IMMUTABLE
66
    AS $$
67
BEGIN
68
    new.result := (
69
        SELECT functions.join_strs('; ', value)
70
        FROM
71
        (
72
            SELECT *
73
            FROM
74
            (
75
                SELECT
76
                DISTINCT ON (value)
77
                *
78
                FROM
79
                (VALUES
80
                      (0, new."0")
81
                    , (1, new."1")
82
                    , (2, new."2")
83
                    , (3, new."3")
84
                    , (4, new."4")
85
                    , (5, new."5")
86
                    , (6, new."6")
87
                    , (7, new."7")
88
                    , (8, new."8")
89
                    , (9, new."9")
90
                )
91
                AS v (sort_order, value)
92
            )
93
            AS v
94
            ORDER BY sort_order
95
        )
96
        AS v
97
    );
98
    RETURN new;
99
END;
100
$$;
101

    
102

    
103
--
104
-- Name: _nullIf(); Type: FUNCTION; Schema: functions; Owner: -
105
--
106

    
107
CREATE FUNCTION "_nullIf"() RETURNS trigger
108
    LANGUAGE plpgsql IMMUTABLE
109
    AS $$
110
BEGIN
111
    IF new.type = 'str' THEN -- no cast needed
112
        new.result := (SELECT nullif(new.value, new."null"));
113
    -- Invalid value -> warning, but invalid null value -> error
114
    ELSIF new.type = 'float' THEN
115
        new.result := (SELECT nullif(functions."double precision"(new.value),
116
            new."null"::double precision));
117
    END IF;
118
    
119
    RETURN new;
120
END;
121
$$;
122

    
123

    
124
--
125
-- Name: boolean(text); Type: FUNCTION; Schema: functions; Owner: -
126
--
127

    
128
CREATE FUNCTION "boolean"(value text) RETURNS boolean
129
    LANGUAGE plpgsql IMMUTABLE STRICT
130
    AS $$
131
BEGIN
132
    RETURN value::boolean;
133
EXCEPTION
134
    WHEN data_exception THEN
135
        RAISE WARNING '%', SQLERRM;
136
        RETURN NULL;
137
END;
138
$$;
139

    
140

    
141
--
142
-- Name: double precision(text); Type: FUNCTION; Schema: functions; Owner: -
143
--
144

    
145
CREATE FUNCTION "double precision"(value text) RETURNS double precision
146
    LANGUAGE plpgsql IMMUTABLE STRICT
147
    AS $$
148
BEGIN
149
    RETURN value::double precision;
150
EXCEPTION
151
    WHEN data_exception THEN
152
        RAISE WARNING '%', SQLERRM;
153
        RETURN NULL;
154
END;
155
$$;
156

    
157

    
158
--
159
-- Name: ensure_not_null(text); Type: FUNCTION; Schema: functions; Owner: -
160
--
161

    
162
CREATE FUNCTION ensure_not_null(value text) RETURNS text
163
    LANGUAGE sql IMMUTABLE
164
    AS $_$
165
SELECT COALESCE($1, E'\\N');
166
$_$;
167

    
168

    
169
--
170
-- Name: join_strs_(text, text, text); Type: FUNCTION; Schema: functions; Owner: -
171
--
172

    
173
CREATE FUNCTION join_strs_(state text, delim text, value text) RETURNS text
174
    LANGUAGE sql IMMUTABLE
175
    AS $_$
176
SELECT $1 || (CASE
177
WHEN $1 = '' OR $3 IS NULL OR $3 = ''
178
THEN ''
179
ELSE $2
180
END) || coalesce($3, '');
181
$_$;
182

    
183

    
184
--
185
-- Name: timestamp with time zone(text); Type: FUNCTION; Schema: functions; Owner: -
186
--
187

    
188
CREATE FUNCTION "timestamp with time zone"(value text) RETURNS timestamp with time zone
189
    LANGUAGE plpgsql IMMUTABLE STRICT
190
    AS $$
191
BEGIN
192
    RETURN value::timestamp with time zone;
193
EXCEPTION
194
    WHEN data_exception THEN
195
        RAISE WARNING '%', SQLERRM;
196
        RETURN NULL;
197
END;
198
$$;
199

    
200

    
201
--
202
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: -
203
--
204

    
205
CREATE AGGREGATE join_strs(text, text) (
206
    SFUNC = join_strs_,
207
    STYPE = text,
208
    INITCOND = ''
209
);
210

    
211

    
212
SET default_tablespace = '';
213

    
214
SET default_with_oids = false;
215

    
216
--
217
-- Name: _alt; Type: TABLE; Schema: functions; Owner: -; Tablespace: 
218
--
219

    
220
CREATE TABLE _alt (
221
    result text,
222
    not_null_col boolean DEFAULT true NOT NULL,
223
    "0" text,
224
    "1" text,
225
    "2" text,
226
    "3" text,
227
    "4" text,
228
    "5" text,
229
    "6" text,
230
    "7" text,
231
    "8" text,
232
    "9" text
233
);
234

    
235

    
236
--
237
-- Name: _label; Type: TABLE; Schema: functions; Owner: -; Tablespace: 
238
--
239

    
240
CREATE TABLE _label (
241
    result text,
242
    not_null_col boolean DEFAULT true NOT NULL,
243
    label text,
244
    value text
245
);
246

    
247

    
248
--
249
-- Name: _merge; Type: TABLE; Schema: functions; Owner: -; Tablespace: 
250
--
251

    
252
CREATE TABLE _merge (
253
    result text,
254
    not_null_col boolean DEFAULT true NOT NULL,
255
    "0" text,
256
    "1" text,
257
    "2" text,
258
    "3" text,
259
    "4" text,
260
    "5" text,
261
    "6" text,
262
    "7" text,
263
    "8" text,
264
    "9" text
265
);
266

    
267

    
268
--
269
-- Name: _nullIf; Type: TABLE; Schema: functions; Owner: -; Tablespace: 
270
--
271

    
272
CREATE TABLE "_nullIf" (
273
    result text,
274
    not_null_col boolean DEFAULT true NOT NULL,
275
    "null" text,
276
    type datatype DEFAULT 'str'::datatype NOT NULL,
277
    value text
278
);
279

    
280

    
281
--
282
-- Name: _alt_0; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
283
--
284

    
285
CREATE INDEX _alt_0 ON _alt USING btree ("0");
286

    
287

    
288
--
289
-- Name: _alt_1; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
290
--
291

    
292
CREATE INDEX _alt_1 ON _alt USING btree ("1");
293

    
294

    
295
--
296
-- Name: _alt_2; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
297
--
298

    
299
CREATE INDEX _alt_2 ON _alt USING btree ("2");
300

    
301

    
302
--
303
-- Name: _alt_3; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
304
--
305

    
306
CREATE INDEX _alt_3 ON _alt USING btree ("3");
307

    
308

    
309
--
310
-- Name: _alt_4; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
311
--
312

    
313
CREATE INDEX _alt_4 ON _alt USING btree ("4");
314

    
315

    
316
--
317
-- Name: _alt_5; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
318
--
319

    
320
CREATE INDEX _alt_5 ON _alt USING btree ("5");
321

    
322

    
323
--
324
-- Name: _alt_6; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
325
--
326

    
327
CREATE INDEX _alt_6 ON _alt USING btree ("6");
328

    
329

    
330
--
331
-- Name: _alt_7; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
332
--
333

    
334
CREATE INDEX _alt_7 ON _alt USING btree ("7");
335

    
336

    
337
--
338
-- Name: _alt_8; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
339
--
340

    
341
CREATE INDEX _alt_8 ON _alt USING btree ("8");
342

    
343

    
344
--
345
-- Name: _alt_9; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
346
--
347

    
348
CREATE INDEX _alt_9 ON _alt USING btree ("9");
349

    
350

    
351
--
352
-- Name: _alt_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
353
--
354

    
355
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"));
356

    
357

    
358
--
359
-- Name: _label_label; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
360
--
361

    
362
CREATE INDEX _label_label ON _label USING btree (label);
363

    
364

    
365
--
366
-- Name: _label_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
367
--
368

    
369
CREATE UNIQUE INDEX _label_unique ON _label USING btree (ensure_not_null(label), ensure_not_null(value));
370

    
371

    
372
--
373
-- Name: _label_value; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
374
--
375

    
376
CREATE INDEX _label_value ON _label USING btree (value);
377

    
378

    
379
--
380
-- Name: _merge_0; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
381
--
382

    
383
CREATE INDEX _merge_0 ON _merge USING btree ("0");
384

    
385

    
386
--
387
-- Name: _merge_1; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
388
--
389

    
390
CREATE INDEX _merge_1 ON _merge USING btree ("1");
391

    
392

    
393
--
394
-- Name: _merge_2; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
395
--
396

    
397
CREATE INDEX _merge_2 ON _merge USING btree ("2");
398

    
399

    
400
--
401
-- Name: _merge_3; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
402
--
403

    
404
CREATE INDEX _merge_3 ON _merge USING btree ("3");
405

    
406

    
407
--
408
-- Name: _merge_4; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
409
--
410

    
411
CREATE INDEX _merge_4 ON _merge USING btree ("4");
412

    
413

    
414
--
415
-- Name: _merge_5; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
416
--
417

    
418
CREATE INDEX _merge_5 ON _merge USING btree ("5");
419

    
420

    
421
--
422
-- Name: _merge_6; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
423
--
424

    
425
CREATE INDEX _merge_6 ON _merge USING btree ("6");
426

    
427

    
428
--
429
-- Name: _merge_7; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
430
--
431

    
432
CREATE INDEX _merge_7 ON _merge USING btree ("7");
433

    
434

    
435
--
436
-- Name: _merge_8; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
437
--
438

    
439
CREATE INDEX _merge_8 ON _merge USING btree ("8");
440

    
441

    
442
--
443
-- Name: _merge_9; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
444
--
445

    
446
CREATE INDEX _merge_9 ON _merge USING btree ("9");
447

    
448

    
449
--
450
-- Name: _merge_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
451
--
452

    
453
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"));
454

    
455

    
456
--
457
-- Name: _nullIf_null; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
458
--
459

    
460
CREATE INDEX "_nullIf_null" ON "_nullIf" USING btree ("null");
461

    
462

    
463
--
464
-- Name: _nullIf_type; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
465
--
466

    
467
CREATE INDEX "_nullIf_type" ON "_nullIf" USING btree (type);
468

    
469

    
470
--
471
-- Name: _nullIf_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
472
--
473

    
474
CREATE UNIQUE INDEX "_nullIf_unique" ON "_nullIf" USING btree (ensure_not_null("null"), type, ensure_not_null(value));
475

    
476

    
477
--
478
-- Name: _nullIf_value; Type: INDEX; Schema: functions; Owner: -; Tablespace: 
479
--
480

    
481
CREATE INDEX "_nullIf_value" ON "_nullIf" USING btree (value);
482

    
483

    
484
--
485
-- Name: _alt; Type: TRIGGER; Schema: functions; Owner: -
486
--
487

    
488
CREATE TRIGGER _alt BEFORE INSERT OR UPDATE ON _alt FOR EACH ROW EXECUTE PROCEDURE _alt();
489

    
490

    
491
--
492
-- Name: _label; Type: TRIGGER; Schema: functions; Owner: -
493
--
494

    
495
CREATE TRIGGER _label BEFORE INSERT OR UPDATE ON _label FOR EACH ROW EXECUTE PROCEDURE _label();
496

    
497

    
498
--
499
-- Name: _merge; Type: TRIGGER; Schema: functions; Owner: -
500
--
501

    
502
CREATE TRIGGER _merge BEFORE INSERT OR UPDATE ON _merge FOR EACH ROW EXECUTE PROCEDURE _merge();
503

    
504

    
505
--
506
-- Name: _nullIf; Type: TRIGGER; Schema: functions; Owner: -
507
--
508

    
509
CREATE TRIGGER "_nullIf" BEFORE INSERT OR UPDATE ON "_nullIf" FOR EACH ROW EXECUTE PROCEDURE "_nullIf"();
510

    
511

    
512
--
513
-- PostgreSQL database dump complete
514
--
515

    
(4-4/22)