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(text, text, text, text, text, text, text, text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
33
|
--
|
34
|
|
35
|
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
|
36
|
LANGUAGE sql IMMUTABLE
|
37
|
AS $_$
|
38
|
SELECT coalesce($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
39
|
$_$;
|
40
|
|
41
|
|
42
|
--
|
43
|
-- Name: _eq(anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
44
|
--
|
45
|
|
46
|
CREATE FUNCTION _eq("left" anyelement DEFAULT NULL::unknown, "right" anyelement DEFAULT NULL::unknown) RETURNS boolean
|
47
|
LANGUAGE sql IMMUTABLE
|
48
|
AS $_$
|
49
|
SELECT $1 = $2
|
50
|
$_$;
|
51
|
|
52
|
|
53
|
--
|
54
|
-- Name: _label(text, text); Type: FUNCTION; Schema: functions; Owner: -
|
55
|
--
|
56
|
|
57
|
CREATE FUNCTION _label(label text, value text) RETURNS text
|
58
|
LANGUAGE plpgsql IMMUTABLE
|
59
|
AS $$
|
60
|
DECLARE
|
61
|
label text NOT NULL := label; -- add NOT NULL
|
62
|
BEGIN
|
63
|
RETURN label||': '||value;
|
64
|
END;
|
65
|
$$;
|
66
|
|
67
|
|
68
|
--
|
69
|
-- Name: _merge(text, text, text, text, text, text, text, text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
70
|
--
|
71
|
|
72
|
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
|
73
|
LANGUAGE sql IMMUTABLE
|
74
|
AS $_$
|
75
|
SELECT functions.join_strs(value, '; ')
|
76
|
FROM
|
77
|
(
|
78
|
SELECT *
|
79
|
FROM
|
80
|
(
|
81
|
SELECT
|
82
|
DISTINCT ON (value)
|
83
|
*
|
84
|
FROM
|
85
|
(VALUES
|
86
|
(1, $1)
|
87
|
, (2, $2)
|
88
|
, (3, $3)
|
89
|
, (4, $4)
|
90
|
, (5, $5)
|
91
|
, (6, $6)
|
92
|
, (7, $7)
|
93
|
, (8, $8)
|
94
|
, (9, $9)
|
95
|
, (10, $10)
|
96
|
)
|
97
|
AS v (sort_order, value)
|
98
|
WHERE value IS NOT NULL
|
99
|
)
|
100
|
AS v
|
101
|
ORDER BY sort_order
|
102
|
)
|
103
|
AS v
|
104
|
$_$;
|
105
|
|
106
|
|
107
|
--
|
108
|
-- Name: _nullIf(text, text, datatype); Type: FUNCTION; Schema: functions; Owner: -
|
109
|
--
|
110
|
|
111
|
CREATE FUNCTION "_nullIf"(value text, "null" text, type datatype DEFAULT 'str'::datatype) RETURNS text
|
112
|
LANGUAGE plpgsql IMMUTABLE
|
113
|
AS $$
|
114
|
DECLARE
|
115
|
"null" text NOT NULL := "null"; -- add NOT NULL
|
116
|
type functions.datatype NOT NULL := type; -- add NOT NULL
|
117
|
BEGIN
|
118
|
IF type = 'str' THEN RETURN nullif(value, "null"); -- no cast needed
|
119
|
-- Invalid value is ignored, but invalid null value generates error
|
120
|
ELSIF type = 'float' THEN
|
121
|
DECLARE
|
122
|
-- Outside the try block so that invalid null value generates error
|
123
|
"null" double precision := "null"::double precision;
|
124
|
BEGIN
|
125
|
RETURN nullif(value::double precision, "null");
|
126
|
EXCEPTION
|
127
|
WHEN data_exception THEN RETURN value; -- ignore invalid value
|
128
|
END;
|
129
|
END IF;
|
130
|
END;
|
131
|
$$;
|
132
|
|
133
|
|
134
|
--
|
135
|
-- Name: join_strs_transform(text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
136
|
--
|
137
|
|
138
|
CREATE FUNCTION join_strs_transform(state text, value text, delim text) RETURNS text
|
139
|
LANGUAGE sql IMMUTABLE STRICT
|
140
|
AS $_$
|
141
|
SELECT $1 || $3 || $2
|
142
|
$_$;
|
143
|
|
144
|
|
145
|
--
|
146
|
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: -
|
147
|
--
|
148
|
|
149
|
CREATE AGGREGATE join_strs(text, text) (
|
150
|
SFUNC = join_strs_transform,
|
151
|
STYPE = text
|
152
|
);
|
153
|
|
154
|
|
155
|
--
|
156
|
-- PostgreSQL database dump complete
|
157
|
--
|
158
|
|