1
|
--
|
2
|
-- PostgreSQL database dump
|
3
|
--
|
4
|
|
5
|
SET statement_timeout = 0;
|
6
|
SET lock_timeout = 0;
|
7
|
SET client_encoding = 'UTF8';
|
8
|
SET standard_conforming_strings = on;
|
9
|
SET check_function_bodies = false;
|
10
|
SET client_min_messages = warning;
|
11
|
|
12
|
SET search_path = "SALVIAS", pg_catalog;
|
13
|
|
14
|
--
|
15
|
-- Name: _plots_01_count_of_projects; Type: VIEW; Schema: SALVIAS; Owner: -
|
16
|
--
|
17
|
|
18
|
CREATE VIEW _plots_01_count_of_projects AS
|
19
|
SELECT count(*) AS projects
|
20
|
FROM projects;
|
21
|
|
22
|
|
23
|
--
|
24
|
-- Name: _plots_02_list_of_project_names; Type: VIEW; Schema: SALVIAS; Owner: -
|
25
|
--
|
26
|
|
27
|
CREATE VIEW _plots_02_list_of_project_names AS
|
28
|
SELECT projects.project_name
|
29
|
FROM projects;
|
30
|
|
31
|
|
32
|
--
|
33
|
-- Name: _plots_03_count_of_all_plots_in_this_source; Type: VIEW; Schema: SALVIAS; Owner: -
|
34
|
--
|
35
|
|
36
|
CREATE VIEW _plots_03_count_of_all_plots_in_this_source AS
|
37
|
SELECT count(DISTINCT (pm."SiteCode")::text) AS plots
|
38
|
FROM (projects p
|
39
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)));
|
40
|
|
41
|
|
42
|
--
|
43
|
-- Name: _plots_04_count_of_plots_in_each_project_in_this_source; Type: VIEW; Schema: SALVIAS; Owner: -
|
44
|
--
|
45
|
|
46
|
CREATE VIEW _plots_04_count_of_plots_in_each_project_in_this_source AS
|
47
|
SELECT p.project_name,
|
48
|
count(*) AS plots
|
49
|
FROM (projects p
|
50
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
51
|
GROUP BY p.project_name;
|
52
|
|
53
|
|
54
|
--
|
55
|
-- Name: _plots_05_list_of_plot_codes_by_project; Type: VIEW; Schema: SALVIAS; Owner: -
|
56
|
--
|
57
|
|
58
|
CREATE VIEW _plots_05_list_of_plot_codes_by_project AS
|
59
|
SELECT p.project_name,
|
60
|
(pm."SiteCode")::text AS plot_code
|
61
|
FROM (projects p
|
62
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)));
|
63
|
|
64
|
|
65
|
--
|
66
|
-- Name: _plots_06_list_of_plots_with_stem_measurements; Type: VIEW; Schema: SALVIAS; Owner: -
|
67
|
--
|
68
|
|
69
|
CREATE VIEW _plots_06_list_of_plots_with_stem_measurements AS
|
70
|
SELECT DISTINCT p.project_name,
|
71
|
(pm."SiteCode")::text AS plot_code
|
72
|
FROM (((projects p
|
73
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
74
|
JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
|
75
|
JOIN stems s ON ((po."PlotObsID" = s.plotobs_id)))
|
76
|
GROUP BY p.project_name, (pm."SiteCode")::text
|
77
|
ORDER BY p.project_name, (pm."SiteCode")::text;
|
78
|
|
79
|
|
80
|
--
|
81
|
-- Name: _plots_07_list_of_plots_with_counts_of_individuals_per_species; Type: VIEW; Schema: SALVIAS; Owner: -
|
82
|
--
|
83
|
|
84
|
CREATE VIEW _plots_07_list_of_plots_with_counts_of_individuals_per_species AS
|
85
|
SELECT DISTINCT p.project_name,
|
86
|
(pm."SiteCode")::text AS plot_code
|
87
|
FROM ((projects p
|
88
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
89
|
JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND (po."NoInd" > 1))))
|
90
|
GROUP BY p.project_name, (pm."SiteCode")::text
|
91
|
ORDER BY p.project_name, (pm."SiteCode")::text;
|
92
|
|
93
|
|
94
|
--
|
95
|
-- Name: _plots_08_list_of_plots_which_use_percent_cover; Type: VIEW; Schema: SALVIAS; Owner: -
|
96
|
--
|
97
|
|
98
|
CREATE VIEW _plots_08_list_of_plots_which_use_percent_cover AS
|
99
|
SELECT DISTINCT p.project_name,
|
100
|
(pm."SiteCode")::text AS plot_code
|
101
|
FROM ((projects p
|
102
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
103
|
JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND (po.cover_percent IS NOT NULL))))
|
104
|
GROUP BY p.project_name, (pm."SiteCode")::text
|
105
|
ORDER BY p.project_name, (pm."SiteCode")::text;
|
106
|
|
107
|
|
108
|
--
|
109
|
-- Name: _plots_09_list_of_plots_which_use_line_intercept; Type: VIEW; Schema: SALVIAS; Owner: -
|
110
|
--
|
111
|
|
112
|
CREATE VIEW _plots_09_list_of_plots_which_use_line_intercept AS
|
113
|
SELECT DISTINCT p.project_name,
|
114
|
(pm."SiteCode")::text AS plot_code
|
115
|
FROM ((projects p
|
116
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
117
|
JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND (po.intercept_cm IS NOT NULL))))
|
118
|
GROUP BY p.project_name, (pm."SiteCode")::text
|
119
|
ORDER BY p.project_name, (pm."SiteCode")::text;
|
120
|
|
121
|
|
122
|
--
|
123
|
-- Name: _plots_10_count_of_individuals_per_plot_in_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
|
124
|
--
|
125
|
|
126
|
CREATE VIEW _plots_10_count_of_individuals_per_plot_in_each_project AS
|
127
|
SELECT p.project_name,
|
128
|
(pm."SiteCode")::text AS plot_code,
|
129
|
sum(po."NoInd") AS individuals
|
130
|
FROM ((projects p
|
131
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
132
|
JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
|
133
|
GROUP BY p.project_name, (pm."SiteCode")::text
|
134
|
ORDER BY p.project_name, (pm."SiteCode")::text;
|
135
|
|
136
|
|
137
|
--
|
138
|
-- Name: VIEW _plots_10_count_of_individuals_per_plot_in_each_project; Type: COMMENT; Schema: SALVIAS; Owner: -
|
139
|
--
|
140
|
|
141
|
COMMENT ON VIEW _plots_10_count_of_individuals_per_plot_in_each_project IS '
|
142
|
Method: Sum on NoInd (number of individuals) column.
|
143
|
Note 1: `individuals` should be NULL for plots which use percent cover or line-intercept methods.
|
144
|
Note 2: Do not count records in plotObservations table, as this will give incorrect total for plots such as Gentry plot, which count individuals per species per subplot
|
145
|
';
|
146
|
|
147
|
|
148
|
--
|
149
|
-- Name: _plots_11_count_of_stems_per_plot_in_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
|
150
|
--
|
151
|
|
152
|
CREATE VIEW _plots_11_count_of_stems_per_plot_in_each_project AS
|
153
|
SELECT p.project_name,
|
154
|
(pm."SiteCode")::text AS plot_code,
|
155
|
count(DISTINCT s.stem_id) AS stems
|
156
|
FROM (((projects p
|
157
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
158
|
JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
|
159
|
JOIN stems s ON ((po."PlotObsID" = s.plotobs_id)))
|
160
|
GROUP BY p.project_name, (pm."SiteCode")::text
|
161
|
ORDER BY p.project_name, (pm."SiteCode")::text;
|
162
|
|
163
|
|
164
|
--
|
165
|
-- Name: VIEW _plots_11_count_of_stems_per_plot_in_each_project; Type: COMMENT; Schema: SALVIAS; Owner: -
|
166
|
--
|
167
|
|
168
|
COMMENT ON VIEW _plots_11_count_of_stems_per_plot_in_each_project IS '
|
169
|
Method: count records in stems table
|
170
|
';
|
171
|
|
172
|
|
173
|
--
|
174
|
-- Name: _plots_12_count_of_verbatim_taxa_per_plot_in_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
|
175
|
--
|
176
|
|
177
|
CREATE VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project AS
|
178
|
SELECT a.project_name,
|
179
|
a.plot_code,
|
180
|
count(a.taxon) AS taxa
|
181
|
FROM ( SELECT DISTINCT p.project_name,
|
182
|
(pm."SiteCode")::text AS plot_code,
|
183
|
btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text)))))) AS taxon
|
184
|
FROM ((projects p
|
185
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
186
|
JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))) a
|
187
|
GROUP BY a.project_name, a.plot_code
|
188
|
ORDER BY a.project_name, a.plot_code;
|
189
|
|
190
|
|
191
|
--
|
192
|
-- Name: VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project; Type: COMMENT; Schema: SALVIAS; Owner: -
|
193
|
--
|
194
|
|
195
|
COMMENT ON VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project IS '
|
196
|
Note: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegBIEN
|
197
|
';
|
198
|
|
199
|
|
200
|
--
|
201
|
-- Name: _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p; Type: VIEW; Schema: SALVIAS; Owner: -
|
202
|
--
|
203
|
|
204
|
CREATE VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p AS
|
205
|
SELECT DISTINCT p.project_name,
|
206
|
(pm."SiteCode")::text AS plot_code,
|
207
|
btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text)))))) AS taxon
|
208
|
FROM ((projects p
|
209
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
210
|
JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
|
211
|
ORDER BY p.project_name, (pm."SiteCode")::text, btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text))))));
|
212
|
|
213
|
|
214
|
--
|
215
|
-- Name: VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p; Type: COMMENT; Schema: SALVIAS; Owner: -
|
216
|
--
|
217
|
|
218
|
COMMENT ON VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p IS '
|
219
|
Note: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegBIEN.
|
220
|
';
|
221
|
|
222
|
|
223
|
--
|
224
|
-- Name: _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr; Type: VIEW; Schema: SALVIAS; Owner: -
|
225
|
--
|
226
|
|
227
|
CREATE VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr AS
|
228
|
SELECT DISTINCT p.project_name,
|
229
|
(pm."SiteCode")::text AS plot_code,
|
230
|
btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text)))))) AS taxon,
|
231
|
sum(po."NoInd") AS individuals
|
232
|
FROM ((projects p
|
233
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
234
|
JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
|
235
|
GROUP BY p.project_name, (pm."SiteCode")::text, btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text))))))
|
236
|
ORDER BY p.project_name, (pm."SiteCode")::text, btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text))))));
|
237
|
|
238
|
|
239
|
--
|
240
|
-- Name: VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr; Type: COMMENT; Schema: SALVIAS; Owner: -
|
241
|
--
|
242
|
|
243
|
COMMENT ON VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr IS '
|
244
|
Note: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegBIEN
|
245
|
';
|
246
|
|
247
|
|
248
|
--
|
249
|
-- Name: _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro; Type: VIEW; Schema: SALVIAS; Owner: -
|
250
|
--
|
251
|
|
252
|
CREATE VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro AS
|
253
|
SELECT DISTINCT p.project_name,
|
254
|
(pm."SiteCode")::text AS plot_code,
|
255
|
btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text)))))) AS taxon,
|
256
|
avg(po.cover_percent) AS mean_cover
|
257
|
FROM ((projects p
|
258
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
259
|
JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND (po.cover_percent IS NOT NULL))))
|
260
|
GROUP BY p.project_name, (pm."SiteCode")::text, btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text))))))
|
261
|
ORDER BY p.project_name, (pm."SiteCode")::text, btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text))))));
|
262
|
|
263
|
|
264
|
--
|
265
|
-- Name: VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro; Type: COMMENT; Schema: SALVIAS; Owner: -
|
266
|
--
|
267
|
|
268
|
COMMENT ON VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro IS '
|
269
|
Note 1: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegbien
|
270
|
Note 2: Grouping mean cover for entire plot allows inclusion of plots with subplots (separate cover measure for each species in each subplot), plots with strata (separate cover measures for each species in each stratum), and plots without subplots or strata (one cover measure per species per plot) in same query.
|
271
|
Note 3: currently, there are no SALVIAS percent cover plots in BIEN
|
272
|
';
|
273
|
|
274
|
|
275
|
--
|
276
|
-- Name: _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj; Type: VIEW; Schema: SALVIAS; Owner: -
|
277
|
--
|
278
|
|
279
|
CREATE VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj AS
|
280
|
SELECT DISTINCT p.project_name,
|
281
|
(pm."SiteCode")::text AS plot_code,
|
282
|
btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text)))))) AS taxon,
|
283
|
po.intercept_cm
|
284
|
FROM ((projects p
|
285
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
286
|
JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND (po.intercept_cm IS NOT NULL))))
|
287
|
ORDER BY p.project_name, (pm."SiteCode")::text, btrim(concat_ws(' '::text, ifnull(po."Family", ''::text), ifnull(po."Genus", ''::text), ifnull(po."Species", ''::text), if((po.infra_ep_1 IS NULL), ifnull(po.auth, ''::text), btrim(concat_ws(' '::text, ifnull(po.infra_rank_1, ''::text), ifnull(po.infra_ep_1, ''::text), ifnull(po.infra_auth_1, ''::text))))));
|
288
|
|
289
|
|
290
|
--
|
291
|
-- Name: VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj; Type: COMMENT; Schema: SALVIAS; Owner: -
|
292
|
--
|
293
|
|
294
|
COMMENT ON VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj IS '
|
295
|
Note 1: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegbien
|
296
|
Note 2: Grouping mean cover for entire plot combines plots with subplots (separate cover measure for each species in each subplot) with plots with strata (separate cover measures for each species in each stratum) with plots without subplots or strata (one cover measure per species per plot.
|
297
|
';
|
298
|
|
299
|
|
300
|
--
|
301
|
-- Name: _plots_17_count_of_subplots_per_plot_for_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
|
302
|
--
|
303
|
|
304
|
CREATE VIEW _plots_17_count_of_subplots_per_plot_for_each_project AS
|
305
|
SELECT p.project_name,
|
306
|
(pm."SiteCode")::text AS plot_code,
|
307
|
count(DISTINCT po."Line") AS subplots
|
308
|
FROM ((projects p
|
309
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
310
|
JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
|
311
|
GROUP BY p.project_name, (pm."SiteCode")::text
|
312
|
ORDER BY p.project_name, (pm."SiteCode")::text;
|
313
|
|
314
|
|
315
|
--
|
316
|
-- Name: _plots_18_list_of_subplots_codes_for_each_plot_for_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
|
317
|
--
|
318
|
|
319
|
CREATE VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project AS
|
320
|
SELECT DISTINCT p.project_name,
|
321
|
(pm."SiteCode")::text AS plot_code,
|
322
|
po."Line" AS subplot
|
323
|
FROM ((projects p
|
324
|
JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
|
325
|
JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND ((pm."SiteCode")::text IS NOT NULL))))
|
326
|
ORDER BY p.project_name, (pm."SiteCode")::text, po."Line";
|
327
|
|
328
|
|
329
|
--
|
330
|
-- Name: VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project; Type: COMMENT; Schema: SALVIAS; Owner: -
|
331
|
--
|
332
|
|
333
|
COMMENT ON VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project IS '
|
334
|
Note: includes plots with and without subplots
|
335
|
';
|
336
|
|
337
|
|
338
|
--
|
339
|
-- PostgreSQL database dump complete
|
340
|
--
|
341
|
|