Project

General

Profile

1 12406 aaronmk
--
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 12417 aaronmk
 SELECT projects.project_name
29 12406 aaronmk
   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 12508 aaronmk
 SELECT count(DISTINCT (pm."SiteCode")::text) AS plots
38 12406 aaronmk
   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 12538 aaronmk
    (pm."SiteCode")::text AS plot_code
61 12406 aaronmk
   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 12538 aaronmk
    (pm."SiteCode")::text AS plot_code
72 12406 aaronmk
   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 12508 aaronmk
  GROUP BY p.project_name, (pm."SiteCode")::text
77
  ORDER BY p.project_name, (pm."SiteCode")::text;
78 12406 aaronmk
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 12538 aaronmk
    (pm."SiteCode")::text AS plot_code
87 12406 aaronmk
   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 12508 aaronmk
  GROUP BY p.project_name, (pm."SiteCode")::text
91
  ORDER BY p.project_name, (pm."SiteCode")::text;
92 12406 aaronmk
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 12538 aaronmk
    (pm."SiteCode")::text AS plot_code
101 12406 aaronmk
   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 12508 aaronmk
  GROUP BY p.project_name, (pm."SiteCode")::text
105
  ORDER BY p.project_name, (pm."SiteCode")::text;
106 12406 aaronmk
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 12538 aaronmk
    (pm."SiteCode")::text AS plot_code
115 12406 aaronmk
   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 12508 aaronmk
  GROUP BY p.project_name, (pm."SiteCode")::text
119
  ORDER BY p.project_name, (pm."SiteCode")::text;
120 12406 aaronmk
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 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
129 12406 aaronmk
    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 12508 aaronmk
  GROUP BY p.project_name, (pm."SiteCode")::text
134
  ORDER BY p.project_name, (pm."SiteCode")::text;
135 12406 aaronmk
136
137
--
138 12407 aaronmk
-- 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 12596 aaronmk
-- Name: _plots_10a_aggregate_observation_individual_counts; Type: VIEW; Schema: SALVIAS; Owner: -
150
--
151
152
CREATE VIEW _plots_10a_aggregate_observation_individual_counts AS
153
 SELECT p.project_name,
154
    (pm."SiteCode")::text AS plot_code,
155 12601 aaronmk
    (po."PlotObsID")::text AS individual_id,
156 12596 aaronmk
    po."NoInd" AS individuals
157
   FROM ((projects p
158
   JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
159
   JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
160 12601 aaronmk
  ORDER BY p.project_name, (pm."SiteCode")::text, (po."PlotObsID")::text;
161 12596 aaronmk
162
163
--
164
-- Name: VIEW _plots_10a_aggregate_observation_individual_counts; Type: COMMENT; Schema: SALVIAS; Owner: -
165
--
166
167
COMMENT ON VIEW _plots_10a_aggregate_observation_individual_counts IS '
168
Note 1: `individuals` should be NULL for plots which use percent cover or line-intercept methods.
169
';
170
171
172
--
173 12406 aaronmk
-- Name: _plots_11_count_of_stems_per_plot_in_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
174
--
175
176
CREATE VIEW _plots_11_count_of_stems_per_plot_in_each_project AS
177
 SELECT p.project_name,
178 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
179 12406 aaronmk
    count(DISTINCT s.stem_id) AS stems
180
   FROM (((projects p
181
   JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
182
   JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
183
   JOIN stems s ON ((po."PlotObsID" = s.plotobs_id)))
184 12508 aaronmk
  GROUP BY p.project_name, (pm."SiteCode")::text
185
  ORDER BY p.project_name, (pm."SiteCode")::text;
186 12406 aaronmk
187
188
--
189 12407 aaronmk
-- Name: VIEW _plots_11_count_of_stems_per_plot_in_each_project; Type: COMMENT; Schema: SALVIAS; Owner: -
190
--
191
192
COMMENT ON VIEW _plots_11_count_of_stems_per_plot_in_each_project IS '
193
Method: count records in stems table
194
';
195
196
197
--
198 12406 aaronmk
-- Name: _plots_12_count_of_verbatim_taxa_per_plot_in_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
199
--
200
201
CREATE VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project AS
202
 SELECT a.project_name,
203 12526 aaronmk
    a.plot_code,
204 12406 aaronmk
    count(a.taxon) AS taxa
205
   FROM ( SELECT DISTINCT p.project_name,
206 12526 aaronmk
            (pm."SiteCode")::text AS plot_code,
207 12406 aaronmk
            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")))) a
211 12526 aaronmk
  GROUP BY a.project_name, a.plot_code
212
  ORDER BY a.project_name, a.plot_code;
213 12406 aaronmk
214
215
--
216 12407 aaronmk
-- Name: VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project; Type: COMMENT; Schema: SALVIAS; Owner: -
217
--
218
219
COMMENT ON VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project IS '
220
Note: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegBIEN
221
';
222
223
224
--
225 12406 aaronmk
-- Name: _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p; Type: VIEW; Schema: SALVIAS; Owner: -
226
--
227
228
CREATE VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p AS
229
 SELECT DISTINCT p.project_name,
230 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
231 12406 aaronmk
    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
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 12508 aaronmk
  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))))));
236 12406 aaronmk
237
238
--
239 12407 aaronmk
-- Name: VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p; Type: COMMENT; Schema: SALVIAS; Owner: -
240
--
241
242
COMMENT ON VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p IS '
243
Note: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegBIEN.
244
';
245
246
247
--
248 12406 aaronmk
-- Name: _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr; Type: VIEW; Schema: SALVIAS; Owner: -
249
--
250
251
CREATE VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr AS
252
 SELECT DISTINCT p.project_name,
253 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
254 12406 aaronmk
    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,
255
    sum(po."NoInd") AS individuals
256
   FROM ((projects p
257
   JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
258
   JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
259 12508 aaronmk
  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))))))
260
  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))))));
261 12406 aaronmk
262
263
--
264 12407 aaronmk
-- Name: VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr; Type: COMMENT; Schema: SALVIAS; Owner: -
265
--
266
267
COMMENT ON VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr IS '
268
Note: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegBIEN
269
';
270
271
272
--
273 12406 aaronmk
-- Name: _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro; Type: VIEW; Schema: SALVIAS; Owner: -
274
--
275
276
CREATE VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro AS
277
 SELECT DISTINCT p.project_name,
278 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
279 12406 aaronmk
    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,
280 12603 aaronmk
    sum((po.cover_percent)::double precision) AS totalpercentcover
281 12406 aaronmk
   FROM ((projects p
282
   JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
283
   JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND (po.cover_percent IS NOT NULL))))
284 12508 aaronmk
  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))))))
285
  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))))));
286 12406 aaronmk
287
288
--
289 12407 aaronmk
-- Name: VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro; Type: COMMENT; Schema: SALVIAS; Owner: -
290
--
291
292
COMMENT ON VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro IS '
293
Note 1: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegbien
294
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.
295
Note 3: currently, there are no SALVIAS percent cover plots in BIEN
296
';
297
298
299
--
300 12406 aaronmk
-- Name: _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj; Type: VIEW; Schema: SALVIAS; Owner: -
301
--
302
303
CREATE VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj AS
304
 SELECT DISTINCT p.project_name,
305 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
306 12406 aaronmk
    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,
307
    po.intercept_cm
308
   FROM ((projects p
309
   JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
310
   JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND (po.intercept_cm IS NOT NULL))))
311 12508 aaronmk
  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))))));
312 12406 aaronmk
313
314
--
315 12407 aaronmk
-- Name: VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj; Type: COMMENT; Schema: SALVIAS; Owner: -
316
--
317
318
COMMENT ON VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj IS '
319
Note 1: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in vegbien
320
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.
321
';
322
323
324
--
325 12406 aaronmk
-- Name: _plots_17_count_of_subplots_per_plot_for_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
326
--
327
328
CREATE VIEW _plots_17_count_of_subplots_per_plot_for_each_project AS
329
 SELECT p.project_name,
330 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
331 12406 aaronmk
    count(DISTINCT po."Line") AS subplots
332
   FROM ((projects p
333
   JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
334
   JOIN "plotObservations" po ON ((pm."PlotID" = po."PlotID")))
335 12508 aaronmk
  GROUP BY p.project_name, (pm."SiteCode")::text
336
  ORDER BY p.project_name, (pm."SiteCode")::text;
337 12406 aaronmk
338
339
--
340
-- Name: _plots_18_list_of_subplots_codes_for_each_plot_for_each_project; Type: VIEW; Schema: SALVIAS; Owner: -
341
--
342
343
CREATE VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project AS
344
 SELECT DISTINCT p.project_name,
345 12526 aaronmk
    (pm."SiteCode")::text AS plot_code,
346 12605 aaronmk
    po."Line" AS subplot_code
347 12406 aaronmk
   FROM ((projects p
348
   JOIN "plotMetadata" pm ON ((p.project_id = pm.project_id)))
349 12508 aaronmk
   JOIN "plotObservations" po ON (((pm."PlotID" = po."PlotID") AND ((pm."SiteCode")::text IS NOT NULL))))
350
  ORDER BY p.project_name, (pm."SiteCode")::text, po."Line";
351 12406 aaronmk
352
353
--
354 12407 aaronmk
-- Name: VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project; Type: COMMENT; Schema: SALVIAS; Owner: -
355
--
356
357
COMMENT ON VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project IS '
358
Note: includes plots with and without subplots
359
';
360
361
362
--
363 12406 aaronmk
-- PostgreSQL database dump complete
364
--