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(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
33
|
--
|
34
|
|
35
|
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
|
36
|
LANGUAGE sql IMMUTABLE
|
37
|
AS $_$
|
38
|
SELECT coalesce($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
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: _frac_to_pct(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
55
|
--
|
56
|
|
57
|
CREATE FUNCTION _frac_to_pct(value double precision) RETURNS double precision
|
58
|
LANGUAGE sql IMMUTABLE STRICT
|
59
|
AS $_$
|
60
|
SELECT $1*100.
|
61
|
$_$;
|
62
|
|
63
|
|
64
|
--
|
65
|
-- Name: _ha_to_m2(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
66
|
--
|
67
|
|
68
|
CREATE FUNCTION _ha_to_m2(value double precision) RETURNS double precision
|
69
|
LANGUAGE sql IMMUTABLE STRICT
|
70
|
AS $_$
|
71
|
SELECT $1*10000.
|
72
|
$_$;
|
73
|
|
74
|
|
75
|
--
|
76
|
-- Name: _ha_to_m2(text); Type: FUNCTION; Schema: functions; Owner: -
|
77
|
--
|
78
|
|
79
|
CREATE FUNCTION _ha_to_m2(value text) RETURNS double precision
|
80
|
LANGUAGE sql IMMUTABLE STRICT
|
81
|
AS $_$
|
82
|
SELECT functions._ha_to_m2($1::double precision)
|
83
|
$_$;
|
84
|
|
85
|
|
86
|
--
|
87
|
-- Name: _if(boolean, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
88
|
--
|
89
|
|
90
|
CREATE FUNCTION _if(cond boolean DEFAULT NULL::boolean, "then" anyelement DEFAULT NULL::unknown, "else" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
91
|
LANGUAGE sql IMMUTABLE
|
92
|
AS $_$
|
93
|
SELECT (CASE WHEN $1 THEN $2 ELSE $3 END)
|
94
|
$_$;
|
95
|
|
96
|
|
97
|
--
|
98
|
-- Name: _if(text, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
99
|
--
|
100
|
|
101
|
CREATE FUNCTION _if(cond text DEFAULT NULL::text, "then" anyelement DEFAULT NULL::unknown, "else" anyelement DEFAULT NULL::unknown) RETURNS anyelement
|
102
|
LANGUAGE sql IMMUTABLE
|
103
|
AS $_$
|
104
|
SELECT functions._if($1 != '', $2, $3)
|
105
|
$_$;
|
106
|
|
107
|
|
108
|
--
|
109
|
-- Name: _join(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
110
|
--
|
111
|
|
112
|
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
|
113
|
LANGUAGE sql IMMUTABLE
|
114
|
AS $_$
|
115
|
SELECT array_to_string(ARRAY[$1, $2, $3, $4, $5, $6, $7, $8, $9, $10], '; ')
|
116
|
$_$;
|
117
|
|
118
|
|
119
|
--
|
120
|
-- Name: _label(anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
121
|
--
|
122
|
|
123
|
CREATE FUNCTION _label(label anyelement, value anyelement) RETURNS anyelement
|
124
|
LANGUAGE sql IMMUTABLE
|
125
|
AS $_$
|
126
|
SELECT coalesce($1 || ': ', '') || $2
|
127
|
$_$;
|
128
|
|
129
|
|
130
|
--
|
131
|
-- Name: _m2_to_ha(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
132
|
--
|
133
|
|
134
|
CREATE FUNCTION _m2_to_ha(value double precision) RETURNS double precision
|
135
|
LANGUAGE sql IMMUTABLE STRICT
|
136
|
AS $_$
|
137
|
SELECT $1/10000.
|
138
|
$_$;
|
139
|
|
140
|
|
141
|
--
|
142
|
-- Name: _merge(anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement, anyelement); Type: FUNCTION; Schema: functions; Owner: -
|
143
|
--
|
144
|
|
145
|
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
|
146
|
LANGUAGE sql IMMUTABLE
|
147
|
AS $_$
|
148
|
SELECT functions.join_strs(value, '; ')
|
149
|
FROM
|
150
|
(
|
151
|
SELECT *
|
152
|
FROM
|
153
|
(
|
154
|
SELECT
|
155
|
DISTINCT ON (value)
|
156
|
*
|
157
|
FROM
|
158
|
(VALUES
|
159
|
(1, $1)
|
160
|
, (2, $2)
|
161
|
, (3, $3)
|
162
|
, (4, $4)
|
163
|
, (5, $5)
|
164
|
, (6, $6)
|
165
|
, (7, $7)
|
166
|
, (8, $8)
|
167
|
, (9, $9)
|
168
|
, (10, $10)
|
169
|
)
|
170
|
AS v (sort_order, value)
|
171
|
WHERE value IS NOT NULL
|
172
|
)
|
173
|
AS v
|
174
|
ORDER BY sort_order
|
175
|
)
|
176
|
AS v
|
177
|
$_$;
|
178
|
|
179
|
|
180
|
--
|
181
|
-- Name: _nullIf(anyelement, text, datatype); Type: FUNCTION; Schema: functions; Owner: -
|
182
|
--
|
183
|
|
184
|
CREATE FUNCTION "_nullIf"(value anyelement, "null" text, type datatype DEFAULT 'str'::datatype) RETURNS anyelement
|
185
|
LANGUAGE plpgsql IMMUTABLE
|
186
|
AS $$
|
187
|
DECLARE
|
188
|
"null" text NOT NULL := "null"; -- add NOT NULL
|
189
|
type functions.datatype NOT NULL := type; -- add NOT NULL
|
190
|
BEGIN
|
191
|
IF type = 'str' THEN RETURN nullif(value::text, "null");
|
192
|
-- Invalid value is ignored, but invalid null value generates error
|
193
|
ELSIF type = 'float' THEN
|
194
|
DECLARE
|
195
|
-- Outside the try block so that invalid null value generates error
|
196
|
"null" double precision := "null"::double precision;
|
197
|
BEGIN
|
198
|
RETURN nullif(value::double precision, "null");
|
199
|
EXCEPTION
|
200
|
WHEN data_exception THEN RETURN value; -- ignore invalid value
|
201
|
END;
|
202
|
END IF;
|
203
|
END;
|
204
|
$$;
|
205
|
|
206
|
|
207
|
--
|
208
|
-- Name: _nullIf(anyelement, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
209
|
--
|
210
|
|
211
|
CREATE FUNCTION "_nullIf"(value anyelement, "null" text, type text) RETURNS anyelement
|
212
|
LANGUAGE sql IMMUTABLE
|
213
|
AS $_$
|
214
|
SELECT functions."_nullIf"($1, $2, $3::functions.datatype)
|
215
|
$_$;
|
216
|
|
217
|
|
218
|
--
|
219
|
-- Name: _pct_to_frac(double precision); Type: FUNCTION; Schema: functions; Owner: -
|
220
|
--
|
221
|
|
222
|
CREATE FUNCTION _pct_to_frac(value double precision) RETURNS double precision
|
223
|
LANGUAGE sql IMMUTABLE STRICT
|
224
|
AS $_$
|
225
|
SELECT $1/100.
|
226
|
$_$;
|
227
|
|
228
|
|
229
|
--
|
230
|
-- Name: _pct_to_frac(text); Type: FUNCTION; Schema: functions; Owner: -
|
231
|
--
|
232
|
|
233
|
CREATE FUNCTION _pct_to_frac(value text) RETURNS double precision
|
234
|
LANGUAGE sql IMMUTABLE STRICT
|
235
|
AS $_$
|
236
|
SELECT functions._pct_to_frac($1::double precision)
|
237
|
$_$;
|
238
|
|
239
|
|
240
|
--
|
241
|
-- Name: join_strs_transform(text, text, text); Type: FUNCTION; Schema: functions; Owner: -
|
242
|
--
|
243
|
|
244
|
CREATE FUNCTION join_strs_transform(state text, value text, delim text) RETURNS text
|
245
|
LANGUAGE sql IMMUTABLE STRICT
|
246
|
AS $_$
|
247
|
SELECT $1 || $3 || $2
|
248
|
$_$;
|
249
|
|
250
|
|
251
|
--
|
252
|
-- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: -
|
253
|
--
|
254
|
|
255
|
CREATE AGGREGATE join_strs(text, text) (
|
256
|
SFUNC = join_strs_transform,
|
257
|
STYPE = text
|
258
|
);
|
259
|
|
260
|
|
261
|
--
|
262
|
-- PostgreSQL database dump complete
|
263
|
--
|
264
|
|