Project

General

Profile

1 2094 aaronmk
--
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 2107 aaronmk
SET search_path = functions, pg_catalog;
20
21 2094 aaronmk
--
22 2566 aaronmk
-- 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 2606 aaronmk
-- Name: _label(); Type: FUNCTION; Schema: functions; Owner: -
38
--
39
40
CREATE FUNCTION _label() RETURNS trigger
41
    LANGUAGE plpgsql IMMUTABLE
42
    AS $$
43
BEGIN
44 2607 aaronmk
    new.result := (SELECT new.label||': '||new.value);
45 2606 aaronmk
    RETURN new;
46
END;
47
$$;
48
49
50
--
51 2596 aaronmk
-- Name: _merge(); Type: FUNCTION; Schema: functions; Owner: -
52
--
53
54
CREATE FUNCTION _merge() RETURNS trigger
55
    LANGUAGE plpgsql IMMUTABLE
56
    AS $$
57
BEGIN
58
    new.result := (
59 2603 aaronmk
        SELECT functions.join_strs('; ', value)
60 2596 aaronmk
        FROM
61 2603 aaronmk
        (
62
            SELECT *
63
            FROM
64
            (
65
                SELECT
66
                DISTINCT ON (value)
67
                *
68
                FROM
69
                (VALUES
70
                      (0, new."0")
71
                    , (1, new."1")
72
                    , (2, new."2")
73
                    , (3, new."3")
74
                    , (4, new."4")
75
                    , (5, new."5")
76
                    , (6, new."6")
77
                    , (7, new."7")
78
                    , (8, new."8")
79
                    , (9, new."9")
80
                )
81
                AS v (sort_order, value)
82
            )
83
            AS v
84
            ORDER BY sort_order
85
        )
86
        AS v
87 2596 aaronmk
    );
88
    RETURN new;
89
END;
90
$$;
91
92
93
--
94 2528 aaronmk
-- Name: boolean(text); Type: FUNCTION; Schema: functions; Owner: -
95
--
96
97
CREATE FUNCTION "boolean"(value text) RETURNS boolean
98 2554 aaronmk
    LANGUAGE plpgsql IMMUTABLE STRICT
99 2528 aaronmk
    AS $$
100
BEGIN
101
    BEGIN
102 2543 aaronmk
        RETURN value::boolean;
103 2528 aaronmk
    EXCEPTION
104
        WHEN data_exception THEN
105
            RAISE WARNING '%', SQLERRM;
106
            RETURN NULL;
107
    END;
108
    RETURN new;
109
END;
110
$$;
111
112
113
--
114
-- Name: double precision(text); Type: FUNCTION; Schema: functions; Owner: -
115
--
116
117
CREATE FUNCTION "double precision"(value text) RETURNS double precision
118 2554 aaronmk
    LANGUAGE plpgsql IMMUTABLE STRICT
119 2528 aaronmk
    AS $$
120
BEGIN
121
    BEGIN
122 2543 aaronmk
        RETURN value::double precision;
123 2528 aaronmk
    EXCEPTION
124
        WHEN data_exception THEN
125
            RAISE WARNING '%', SQLERRM;
126
            RETURN NULL;
127
    END;
128
    RETURN new;
129
END;
130
$$;
131
132
133
--
134 2566 aaronmk
-- Name: ensure_not_null(text); Type: FUNCTION; Schema: functions; Owner: -
135
--
136
137
CREATE FUNCTION ensure_not_null(value text) RETURNS text
138
    LANGUAGE sql IMMUTABLE
139
    AS $_$
140
SELECT COALESCE($1, E'\\N');
141
$_$;
142
143
144
--
145 2595 aaronmk
-- Name: join_strs_(text, text, text); Type: FUNCTION; Schema: functions; Owner: -
146
--
147
148
CREATE FUNCTION join_strs_(state text, delim text, value text) RETURNS text
149
    LANGUAGE sql IMMUTABLE
150
    AS $_$
151
SELECT $1 || (CASE
152
WHEN $1 = '' OR $3 IS NULL OR $3 = ''
153
THEN ''
154
ELSE $2
155
END) || coalesce($3, '');
156
$_$;
157
158
159
--
160 2528 aaronmk
-- Name: timestamp with time zone(text); Type: FUNCTION; Schema: functions; Owner: -
161
--
162
163
CREATE FUNCTION "timestamp with time zone"(value text) RETURNS timestamp with time zone
164 2554 aaronmk
    LANGUAGE plpgsql IMMUTABLE STRICT
165 2528 aaronmk
    AS $$
166
BEGIN
167
    BEGIN
168 2543 aaronmk
        RETURN value::timestamp with time zone;
169 2528 aaronmk
    EXCEPTION
170
        WHEN data_exception THEN
171
            RAISE WARNING '%', SQLERRM;
172
            RETURN NULL;
173
    END;
174
    RETURN new;
175
END;
176
$$;
177
178
179 2595 aaronmk
--
180
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: -
181
--
182
183
CREATE AGGREGATE join_strs(text, text) (
184
    SFUNC = join_strs_,
185
    STYPE = text,
186
    INITCOND = ''
187
);
188
189
190 2566 aaronmk
SET default_tablespace = '';
191
192
SET default_with_oids = false;
193
194 2107 aaronmk
--
195 2566 aaronmk
-- Name: _alt; Type: TABLE; Schema: functions; Owner: -; Tablespace:
196
--
197
198
CREATE TABLE _alt (
199
    result text,
200
    not_null_col boolean DEFAULT true NOT NULL,
201
    "0" text,
202
    "1" text,
203
    "2" text,
204
    "3" text,
205
    "4" text,
206
    "5" text,
207
    "6" text,
208
    "7" text,
209
    "8" text,
210
    "9" text
211
);
212
213
214
--
215 2606 aaronmk
-- Name: _label; Type: TABLE; Schema: functions; Owner: -; Tablespace:
216
--
217
218
CREATE TABLE _label (
219
    result text,
220
    not_null_col boolean DEFAULT true NOT NULL,
221
    label text,
222
    value text
223
);
224
225
226
--
227 2596 aaronmk
-- Name: _merge; Type: TABLE; Schema: functions; Owner: -; Tablespace:
228
--
229
230
CREATE TABLE _merge (
231
    result text,
232
    not_null_col boolean DEFAULT true NOT NULL,
233
    "0" text,
234
    "1" text,
235
    "2" text,
236
    "3" text,
237
    "4" text,
238
    "5" text,
239
    "6" text,
240
    "7" text,
241
    "8" text,
242
    "9" text
243
);
244
245
246
--
247 2566 aaronmk
-- Name: _alt_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
248
--
249
250
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"));
251
252
253
--
254 2606 aaronmk
-- Name: _label_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
255
--
256
257
CREATE UNIQUE INDEX _label_unique ON _label USING btree (ensure_not_null(label), ensure_not_null(value));
258
259
260
--
261 2596 aaronmk
-- Name: _merge_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace:
262
--
263
264
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"));
265
266
267
--
268 2566 aaronmk
-- Name: _alt; Type: TRIGGER; Schema: functions; Owner: -
269
--
270
271
CREATE TRIGGER _alt BEFORE INSERT OR UPDATE ON _alt FOR EACH ROW EXECUTE PROCEDURE _alt();
272
273
274
--
275 2606 aaronmk
-- Name: _label; Type: TRIGGER; Schema: functions; Owner: -
276
--
277
278
CREATE TRIGGER _label BEFORE INSERT OR UPDATE ON _label FOR EACH ROW EXECUTE PROCEDURE _label();
279
280
281
--
282 2596 aaronmk
-- Name: _merge; Type: TRIGGER; Schema: functions; Owner: -
283
--
284
285
CREATE TRIGGER _merge BEFORE INSERT OR UPDATE ON _merge FOR EACH ROW EXECUTE PROCEDURE _merge();
286
287
288
--
289 2136 aaronmk
-- PostgreSQL database dump complete
290
--