20 |
20 |
|
21 |
21 |
SET search_path TO public_validation_plots, public;
|
22 |
22 |
|
23 |
|
-- datasource
|
24 |
|
\set ds '\'SALVIAS\''
|
25 |
|
|
26 |
23 |
-- ------------------
|
27 |
24 |
-- 1. Count of projects
|
28 |
25 |
-- Check: identical count in source db
|
... | ... | |
31 |
28 |
SELECT COUNT(*) AS projects
|
32 |
29 |
FROM project p JOIN source s
|
33 |
30 |
ON p.source_id=s.source_id
|
34 |
|
WHERE s.shortname=:ds;
|
|
31 |
WHERE s.shortname=current_schema;
|
35 |
32 |
|
36 |
33 |
-- ------------------
|
37 |
34 |
-- 2. List of project names
|
... | ... | |
41 |
38 |
SELECT p.projectname
|
42 |
39 |
FROM project p JOIN source s
|
43 |
40 |
ON p.source_id=s.source_id
|
44 |
|
WHERE s.shortname=:ds;
|
|
41 |
WHERE s.shortname=current_schema;
|
45 |
42 |
|
46 |
43 |
-- ------------------
|
47 |
44 |
-- 3. Count of all plots in this source
|
... | ... | |
55 |
52 |
ON p.project_id=le.project_id
|
56 |
53 |
JOIN source s
|
57 |
54 |
ON p.source_id=s.source_id
|
58 |
|
WHERE s.shortname=:ds;
|
|
55 |
WHERE s.shortname=current_schema;
|
59 |
56 |
|
60 |
57 |
-- ------------------
|
61 |
58 |
-- 4. Count of plots in each project in this source
|
... | ... | |
68 |
65 |
ON p.project_id=le.project_id
|
69 |
66 |
JOIN source s
|
70 |
67 |
ON p.source_id=s.source_id
|
71 |
|
WHERE s.shortname=:ds
|
|
68 |
WHERE s.shortname=current_schema
|
72 |
69 |
GROUP BY p.projectname;
|
73 |
70 |
|
74 |
71 |
-- ------------------
|
... | ... | |
83 |
80 |
ON p.project_id=le.project_id
|
84 |
81 |
JOIN source s
|
85 |
82 |
ON p.source_id=s.source_id
|
86 |
|
WHERE s.shortname=:ds;
|
|
83 |
WHERE s.shortname=current_schema;
|
87 |
84 |
|
88 |
85 |
-- ------------------
|
89 |
86 |
-- 6. List of plots with stem measurements
|
... | ... | |
92 |
89 |
|
93 |
90 |
SELECT authorlocationcode
|
94 |
91 |
FROM top_plot
|
95 |
|
WHERE source_id = source_by_shortname(:ds)
|
|
92 |
WHERE source_id = source_by_shortname(current_schema)
|
96 |
93 |
AND EXISTS(
|
97 |
94 |
SELECT NULL
|
98 |
95 |
FROM location
|
... | ... | |
146 |
143 |
join location l on le.location_id=l.location_id
|
147 |
144 |
join taxonoccurrence o on sub_locationevent.locationevent_id=o.locationevent_id
|
148 |
145 |
join aggregateoccurrence ao on o.taxonoccurrence_id=ao.taxonoccurrence_id
|
149 |
|
where s.shortname=:ds
|
|
146 |
where s.shortname=current_schema
|
150 |
147 |
group by p.projectname, l.authorlocationcode
|
151 |
148 |
order by p.projectname, l.authorlocationcode;
|
152 |
149 |
|
... | ... | |
166 |
163 |
join aggregateoccurrence ao on o.taxonoccurrence_id=ao.taxonoccurrence_id
|
167 |
164 |
join plantobservation po on po.aggregateoccurrence_id=ao.aggregateoccurrence_id
|
168 |
165 |
join stemobservation so on so.plantobservation_id=po.plantobservation_id
|
169 |
|
where s.shortname=:ds
|
|
166 |
where s.shortname=current_schema
|
170 |
167 |
group by p.projectname, l.authorlocationcode
|
171 |
168 |
order by p.projectname, l.authorlocationcode;
|
172 |
169 |
|
... | ... | |
188 |
185 |
join taxonoccurrence o on sub_locationevent.locationevent_id=o.locationevent_id
|
189 |
186 |
join taxondetermination td on td.taxonoccurrence_id=o.taxonoccurrence_id
|
190 |
187 |
join taxonverbatim tv on td.taxonverbatim_id=tv.taxonverbatim_id
|
191 |
|
where s.shortname=:ds and td.isoriginal='t'
|
|
188 |
where s.shortname=current_schema and td.isoriginal='t'
|
192 |
189 |
group by p.projectname, l.authorlocationcode
|
193 |
190 |
order by p.projectname, l.authorlocationcode 12;
|
194 |
191 |
|
... | ... | |
208 |
205 |
join taxonoccurrence o on sub_locationevent.locationevent_id=o.locationevent_id
|
209 |
206 |
join taxondetermination td on td.taxonoccurrence_id=o.taxonoccurrence_id
|
210 |
207 |
join taxonverbatim tv on td.taxonverbatim_id=tv.taxonverbatim_id
|
211 |
|
where s.shortname=:ds and td.isoriginal='t'
|
|
208 |
where s.shortname=current_schema and td.isoriginal='t'
|
212 |
209 |
order by p.projectname, l.authorlocationcode, taxon;
|
213 |
210 |
|
214 |
211 |
-- ------------------
|
... | ... | |
229 |
226 |
join taxondetermination td on td.taxonoccurrence_id=o.taxonoccurrence_id
|
230 |
227 |
join taxonverbatim tv on td.taxonverbatim_id=tv.taxonverbatim_id
|
231 |
228 |
join aggregateoccurrence ao on o.taxonoccurrence_id=ao.taxonoccurrence_id
|
232 |
|
where s.shortname=:ds and td.isoriginal='t'
|
|
229 |
where s.shortname=current_schema and td.isoriginal='t'
|
233 |
230 |
group by p.projectname, l.authorlocationcode, taxon
|
234 |
231 |
order by p.projectname, l.authorlocationcode, taxon;
|
235 |
232 |
|
... | ... | |
254 |
251 |
join taxonverbatim tv on td.taxonverbatim_id=tv.taxonverbatim_id
|
255 |
252 |
join aggregateoccurrence ao on o.taxonoccurrence_id=ao.taxonoccurrence_id
|
256 |
253 |
join coverindex ci on ao.coverindex_id=ci.coverindex_id
|
257 |
|
where s.shortname=:ds and td.isoriginal='t'
|
|
254 |
where s.shortname=current_schema and td.isoriginal='t'
|
258 |
255 |
and ci.coverpercent is not null
|
259 |
256 |
group by p.projectname, l.authorlocationcode, taxon
|
260 |
257 |
order by p.projectname, l.authorlocationcode, taxon;
|
... | ... | |
289 |
286 |
join locationevent le on p.project_id=le.project_id
|
290 |
287 |
join locationevent sub_locationevent on sub_locationevent.parent_id=le.locationevent_id
|
291 |
288 |
join location l on le.location_id=l.location_id
|
292 |
|
where s.shortname=:ds
|
|
289 |
where s.shortname=current_schema
|
293 |
290 |
group by p.projectname, l.authorlocationcode
|
294 |
291 |
order by p.projectname, l.authorlocationcode;
|
295 |
292 |
|
... | ... | |
306 |
303 |
join locationevent le on p.project_id=le.project_id
|
307 |
304 |
join locationevent sub_locationevent on sub_locationevent.parent_id=le.locationevent_id
|
308 |
305 |
join location l on sub_locationevent.location_id=l.location_id
|
309 |
|
where s.shortname=:ds
|
|
306 |
where s.shortname=current_schema
|
310 |
307 |
order by p.projectname, l.authorlocationcode;
|
validation/aggregating/*/*.sql: use current_schema instead of a hardcoded datasource name or psql variable