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
|
--
|
20
|
-- Name: SCHEMA functions; Type: COMMENT; Schema: -; Owner: -
|
21
|
--
|
22
|
|
23
|
COMMENT ON SCHEMA functions IS 'IMPORTANT: Functions must always return NULL in place of '''' (the empty string). This ensures that empty strings do not find their way into VegBIEN.';
|
24
|
|
25
|
|
26
|
SET search_path = functions, pg_catalog;
|
27
|
|
28
|
--
|
29
|
-- Name: datatype; Type: TYPE; Schema: functions; Owner: -
|
30
|
--
|
31
|
|
32
|
CREATE TYPE datatype AS ENUM (
|
33
|
'str',
|
34
|
'float'
|
35
|
);
|
36
|
|
37
|
|
38
|
--
|
39
|
-- Name: _alt(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
40
|
--
|
41
|
|
42
|
CREATE FUNCTION _alt("0" anyelement DEFAULT NULL::unknown, "1" anyelement DEFAULT NULL::unknown, "2" anyelement DEFAULT NULL::unknown, "3" anyelement DEFAULT NULL::unknown, "4" anyelement DEFAULT NULL::unknown, "5" anyelement DEFAULT NULL::unknown, "6" anyelement DEFAULT NULL::unknown, "7" anyelement DEFAULT NULL::unknown, "8" anyelement DEFAULT NULL::unknown, "9" anyelement DEFAULT NULL::unknown, "10" anyelement DEFAULT NULL::unknown, "11" anyelement DEFAULT NULL::unknown, "12" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
43
|
LANGUAGE sql IMMUTABLE
|
44
|
AS $_$
|
45
|
SELECT coalesce($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
46
|
$_$;
|
47
|
|
48
|
|
49
|
--
|
50
|
-- Name: _cm_to_m(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
51
|
--
|
52
|
|
53
|
CREATE FUNCTION _cm_to_m(value double precision) RETURNS double precision
|
54
|
LANGUAGE sql IMMUTABLE STRICT
|
55
|
AS $_$
|
56
|
SELECT $1/100.
|
57
|
$_$;
|
58
|
|
59
|
|
60
|
--
|
61
|
-- Name: _cm_to_m(text); Type: FUNCTION; Schema: functions; Owner: -
|
62
|
--
|
63
|
|
64
|
CREATE FUNCTION _cm_to_m(value text) RETURNS double precision
|
65
|
LANGUAGE sql IMMUTABLE STRICT
|
66
|
AS $_$
|
67
|
SELECT functions._cm_to_m($1::double precision)
|
68
|
$_$;
|
69
|
|
70
|
|
71
|
--
|
72
|
-- Name: _eq(anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
73
|
--
|
74
|
|
75
|
CREATE FUNCTION _eq("left" anyelement DEFAULT NULL::unknown, "right" anyelement DEFAULT NULL::unknown) RETURNS boolean
|
76
|
LANGUAGE sql IMMUTABLE
|
77
|
AS $_$
|
78
|
SELECT $1 = $2
|
79
|
$_$;
|
80
|
|
81
|
|
82
|
--
|
83
|
-- Name: _fraction_to_percent(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
84
|
--
|
85
|
|
86
|
CREATE FUNCTION _fraction_to_percent(value double precision) RETURNS double precision
|
87
|
LANGUAGE sql IMMUTABLE STRICT
|
88
|
AS $_$
|
89
|
SELECT $1*100.
|
90
|
$_$;
|
91
|
|
92
|
|
93
|
--
|
94
|
-- Name: _ha_to_m2(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
95
|
--
|
96
|
|
97
|
CREATE FUNCTION _ha_to_m2(value double precision) RETURNS double precision
|
98
|
LANGUAGE sql IMMUTABLE STRICT
|
99
|
AS $_$
|
100
|
SELECT $1*10000.
|
101
|
$_$;
|
102
|
|
103
|
|
104
|
--
|
105
|
-- Name: _ha_to_m2(text); Type: FUNCTION; Schema: functions; Owner: -
|
106
|
--
|
107
|
|
108
|
CREATE FUNCTION _ha_to_m2(value text) RETURNS double precision
|
109
|
LANGUAGE sql IMMUTABLE STRICT
|
110
|
AS $_$
|
111
|
SELECT functions._ha_to_m2($1::double precision)
|
112
|
$_$;
|
113
|
|
114
|
|
115
|
--
|
116
|
-- Name: _if(boolean, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
117
|
--
|
118
|
|
119
|
CREATE FUNCTION _if(cond boolean DEFAULT NULL::boolean, "then" anyelement DEFAULT NULL::unknown, "else" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
120
|
LANGUAGE sql IMMUTABLE
|
121
|
AS $_$
|
122
|
SELECT (CASE WHEN $1 THEN $2 ELSE $3 END)
|
123
|
$_$;
|
124
|
|
125
|
|
126
|
--
|
127
|
-- Name: _if(text, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
128
|
--
|
129
|
|
130
|
CREATE FUNCTION _if(cond text DEFAULT NULL::text, "then" anyelement DEFAULT NULL::unknown, "else" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
131
|
LANGUAGE sql IMMUTABLE
|
132
|
AS $_$
|
133
|
SELECT functions._if($1 != '', $2, $3)
|
134
|
$_$;
|
135
|
|
136
|
|
137
|
--
|
138
|
-- Name: _in_to_m(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
139
|
--
|
140
|
|
141
|
CREATE FUNCTION _in_to_m(value double precision) RETURNS double precision
|
142
|
LANGUAGE sql IMMUTABLE STRICT
|
143
|
AS $_$
|
144
|
SELECT $1*2.54/100.
|
145
|
$_$;
|
146
|
|
147
|
|
148
|
--
|
149
|
-- Name: _in_to_m(text); Type: FUNCTION; Schema: functions; Owner: -
|
150
|
--
|
151
|
|
152
|
CREATE FUNCTION _in_to_m(value text) RETURNS double precision
|
153
|
LANGUAGE sql IMMUTABLE STRICT
|
154
|
AS $_$
|
155
|
SELECT functions._in_to_m($1::double precision)
|
156
|
$_$;
|
157
|
|
158
|
|
159
|
--
|
160
|
-- Name: _join(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
161
|
--
|
162
|
|
163
|
CREATE FUNCTION _join("0" anyelement DEFAULT NULL::unknown, "1" anyelement DEFAULT NULL::unknown, "2" anyelement DEFAULT NULL::unknown, "3" anyelement DEFAULT NULL::unknown, "4" anyelement DEFAULT NULL::unknown, "5" anyelement DEFAULT NULL::unknown, "6" anyelement DEFAULT NULL::unknown, "7" anyelement DEFAULT NULL::unknown, "8" anyelement DEFAULT NULL::unknown, "9" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
164
|
LANGUAGE sql IMMUTABLE
|
165
|
AS $_$
|
166
|
SELECT nullif(array_to_string(ARRAY[$1, $2, $3, $4, $5, $6, $7, $8, $9, $10], '; '), '')
|
167
|
$_$;
|
168
|
|
169
|
|
170
|
--
|
171
|
-- Name: _join_words(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
172
|
--
|
173
|
|
174
|
CREATE FUNCTION _join_words("0" anyelement DEFAULT NULL::unknown, "1" anyelement DEFAULT NULL::unknown, "2" anyelement DEFAULT NULL::unknown, "3" anyelement DEFAULT NULL::unknown, "4" anyelement DEFAULT NULL::unknown, "5" anyelement DEFAULT NULL::unknown, "6" anyelement DEFAULT NULL::unknown, "7" anyelement DEFAULT NULL::unknown, "8" anyelement DEFAULT NULL::unknown, "9" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
175
|
LANGUAGE sql IMMUTABLE
|
176
|
AS $_$
|
177
|
SELECT nullif(array_to_string(ARRAY[$1, $2, $3, $4, $5, $6, $7, $8, $9, $10], ' '), '')
|
178
|
$_$;
|
179
|
|
180
|
|
181
|
--
|
182
|
-- Name: _label(anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
183
|
--
|
184
|
|
185
|
CREATE FUNCTION _label(label anyelement, value anyelement) RETURNS anyelement
|
186
|
LANGUAGE sql IMMUTABLE
|
187
|
AS $_$
|
188
|
SELECT coalesce($1 || ': ', '') || $2
|
189
|
$_$;
|
190
|
|
191
|
|
192
|
--
|
193
|
-- Name: _m2_to_ha(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
194
|
--
|
195
|
|
196
|
CREATE FUNCTION _m2_to_ha(value double precision) RETURNS double precision
|
197
|
LANGUAGE sql IMMUTABLE STRICT
|
198
|
AS $_$
|
199
|
SELECT $1/10000.
|
200
|
$_$;
|
201
|
|
202
|
|
203
|
--
|
204
|
-- Name: _max(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
205
|
--
|
206
|
|
207
|
CREATE FUNCTION _max("0" anyelement DEFAULT NULL::unknown, "1" anyelement DEFAULT NULL::unknown, "2" anyelement DEFAULT NULL::unknown, "3" anyelement DEFAULT NULL::unknown, "4" anyelement DEFAULT NULL::unknown, "5" anyelement DEFAULT NULL::unknown, "6" anyelement DEFAULT NULL::unknown, "7" anyelement DEFAULT NULL::unknown, "8" anyelement DEFAULT NULL::unknown, "9" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
208
|
LANGUAGE sql IMMUTABLE
|
209
|
AS $_$
|
210
|
SELECT max(value)
|
211
|
FROM
|
212
|
(VALUES
|
213
|
($1)
|
214
|
, ($2)
|
215
|
, ($3)
|
216
|
, ($4)
|
217
|
, ($5)
|
218
|
, ($6)
|
219
|
, ($7)
|
220
|
, ($8)
|
221
|
, ($9)
|
222
|
, ($10)
|
223
|
)
|
224
|
AS v (value)
|
225
|
$_$;
|
226
|
|
227
|
|
228
|
--
|
229
|
-- Name: _merge(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
230
|
--
|
231
|
|
232
|
CREATE FUNCTION _merge("0" anyelement DEFAULT NULL::unknown, "1" anyelement DEFAULT NULL::unknown, "2" anyelement DEFAULT NULL::unknown, "3" anyelement DEFAULT NULL::unknown, "4" anyelement DEFAULT NULL::unknown, "5" anyelement DEFAULT NULL::unknown, "6" anyelement DEFAULT NULL::unknown, "7" anyelement DEFAULT NULL::unknown, "8" anyelement DEFAULT NULL::unknown, "9" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
233
|
LANGUAGE sql IMMUTABLE
|
234
|
AS $_$
|
235
|
SELECT functions.join_strs(value, '; ')
|
236
|
FROM
|
237
|
(
|
238
|
SELECT *
|
239
|
FROM
|
240
|
(
|
241
|
SELECT
|
242
|
DISTINCT ON (value)
|
243
|
*
|
244
|
FROM
|
245
|
(VALUES
|
246
|
(1, $1)
|
247
|
, (2, $2)
|
248
|
, (3, $3)
|
249
|
, (4, $4)
|
250
|
, (5, $5)
|
251
|
, (6, $6)
|
252
|
, (7, $7)
|
253
|
, (8, $8)
|
254
|
, (9, $9)
|
255
|
, (10, $10)
|
256
|
)
|
257
|
AS v (sort_order, value)
|
258
|
WHERE value IS NOT NULL
|
259
|
)
|
260
|
AS v
|
261
|
ORDER BY sort_order
|
262
|
)
|
263
|
AS v
|
264
|
$_$;
|
265
|
|
266
|
|
267
|
--
|
268
|
-- Name: _min(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
269
|
--
|
270
|
|
271
|
CREATE FUNCTION _min("0" anyelement DEFAULT NULL::unknown, "1" anyelement DEFAULT NULL::unknown, "2" anyelement DEFAULT NULL::unknown, "3" anyelement DEFAULT NULL::unknown, "4" anyelement DEFAULT NULL::unknown, "5" anyelement DEFAULT NULL::unknown, "6" anyelement DEFAULT NULL::unknown, "7" anyelement DEFAULT NULL::unknown, "8" anyelement DEFAULT NULL::unknown, "9" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
272
|
LANGUAGE sql IMMUTABLE
|
273
|
AS $_$
|
274
|
SELECT min(value)
|
275
|
FROM
|
276
|
(VALUES
|
277
|
($1)
|
278
|
, ($2)
|
279
|
, ($3)
|
280
|
, ($4)
|
281
|
, ($5)
|
282
|
, ($6)
|
283
|
, ($7)
|
284
|
, ($8)
|
285
|
, ($9)
|
286
|
, ($10)
|
287
|
)
|
288
|
AS v (value)
|
289
|
$_$;
|
290
|
|
291
|
|
292
|
--
|
293
|
-- Name: _nullIf(anyelement, text, datatype); Type: FUNCTION; Schema: functions; Owner: -
|
294
|
--
|
295
|
|
296
|
CREATE FUNCTION "_nullIf"(value anyelement, "null" text, type datatype DEFAULT 'str'::datatype) RETURNS anyelement
|
297
|
LANGUAGE plpgsql IMMUTABLE
|
298
|
AS $$
|
299
|
DECLARE
|
300
|
"null" text NOT NULL := "null"; -- add NOT NULL
|
301
|
type functions.datatype NOT NULL := type; -- add NOT NULL
|
302
|
BEGIN
|
303
|
IF type = 'str' THEN RETURN nullif(value::text, "null");
|
304
|
-- Invalid value is ignored, but invalid null value generates error
|
305
|
ELSIF type = 'float' THEN
|
306
|
DECLARE
|
307
|
-- Outside the try block so that invalid null value generates error
|
308
|
"null" double precision := "null"::double precision;
|
309
|
BEGIN
|
310
|
RETURN nullif(value::double precision, "null");
|
311
|
EXCEPTION
|
312
|
WHEN data_exception THEN RETURN value; -- ignore invalid value
|
313
|
END;
|
314
|
END IF;
|
315
|
END;
|
316
|
$$;
|
317
|
|
318
|
|
319
|
--
|
320
|
-- Name: _nullIf(anyelement, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
321
|
--
|
322
|
|
323
|
CREATE FUNCTION "_nullIf"(value anyelement, "null" text, type text) RETURNS anyelement
|
324
|
LANGUAGE sql IMMUTABLE
|
325
|
AS $_$
|
326
|
SELECT functions."_nullIf"($1, $2, $3::functions.datatype)
|
327
|
$_$;
|
328
|
|
329
|
|
330
|
--
|
331
|
-- Name: _percent_to_fraction(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
332
|
--
|
333
|
|
334
|
CREATE FUNCTION _percent_to_fraction(value double precision) RETURNS double precision
|
335
|
LANGUAGE sql IMMUTABLE STRICT
|
336
|
AS $_$
|
337
|
SELECT $1/100.
|
338
|
$_$;
|
339
|
|
340
|
|
341
|
--
|
342
|
-- Name: _percent_to_fraction(text); Type: FUNCTION; Schema: functions; Owner: -
|
343
|
--
|
344
|
|
345
|
CREATE FUNCTION _percent_to_fraction(value text) RETURNS double precision
|
346
|
LANGUAGE sql IMMUTABLE STRICT
|
347
|
AS $_$
|
348
|
SELECT functions._percent_to_fraction($1::double precision)
|
349
|
$_$;
|
350
|
|
351
|
|
352
|
--
|
353
|
-- Name: join_strs_transform(text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
354
|
--
|
355
|
|
356
|
CREATE FUNCTION join_strs_transform(state text, value text, delim text) RETURNS text
|
357
|
LANGUAGE sql IMMUTABLE STRICT
|
358
|
AS $_$
|
359
|
SELECT $1 || $3 || $2
|
360
|
$_$;
|
361
|
|
362
|
|
363
|
--
|
364
|
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: -
|
365
|
--
|
366
|
|
367
|
CREATE AGGREGATE join_strs(text, text) (
|
368
|
SFUNC = join_strs_transform,
|
369
|
STYPE = text
|
370
|
);
|
371
|
|
372
|
|
373
|
--
|
374
|
-- PostgreSQL database dump complete
|
375
|
--
|
376
|
|