Revision 13064
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/validation/aggregating/specimens/qualitative_validations_specimens.sql | ||
---|---|---|
14 | 14 |
SET enable_seqscan = off; |
15 | 15 |
SET join_collapse_limit = 1; -- turn it off |
16 | 16 |
|
17 |
CREATE VIEW _specimens_01_count_of_total_records_specimens_in_source_db AS
|
|
17 |
-- _specimens_01_count_of_total_records_specimens_in_source_db
|
|
18 | 18 |
SELECT count(*) AS "totalSpecimenRecords" |
19 | 19 |
FROM taxonoccurrence |
20 | 20 |
WHERE taxonoccurrence.source_id = (SELECT source_by_shortname(:datasource)) |
21 | 21 |
; |
22 | 22 |
|
23 |
CREATE VIEW _specimens_02_count_of_unique_verbatim_families AS
|
|
23 |
-- _specimens_02_count_of_unique_verbatim_families
|
|
24 | 24 |
SELECT count(DISTINCT family) AS families |
25 | 25 |
FROM taxonverbatim |
26 | 26 |
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource)) |
27 | 27 |
AND family IS NOT NULL |
28 | 28 |
; |
29 | 29 |
|
30 |
CREATE VIEW _specimens_03_list_of_verbatim_families AS
|
|
30 |
-- _specimens_03_list_of_verbatim_families
|
|
31 | 31 |
SELECT DISTINCT family |
32 | 32 |
FROM taxonverbatim |
33 | 33 |
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource)) |
34 | 34 |
AND family IS NOT NULL |
35 | 35 |
; |
36 | 36 |
|
37 |
CREATE VIEW _specimens_04_count_of_species_binomials AS
|
|
37 |
-- _specimens_04_count_of_species_binomials
|
|
38 | 38 |
SELECT count(DISTINCT concat_ws(' '::text, genus, specific_epithet)) AS species_binomials |
39 | 39 |
FROM taxonverbatim |
40 | 40 |
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource)) |
41 | 41 |
AND genus IS NOT NULL AND specific_epithet IS NOT NULL; |
42 | 42 |
; |
43 | 43 |
|
44 |
CREATE VIEW _specimens_05_list_of_species_binomials AS
|
|
44 |
-- _specimens_05_list_of_species_binomials
|
|
45 | 45 |
SELECT DISTINCT concat_ws(' '::text, genus, specific_epithet) AS species_binomial |
46 | 46 |
FROM taxonverbatim |
47 | 47 |
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource)) |
48 | 48 |
AND genus IS NOT NULL AND specific_epithet IS NOT NULL; |
49 | 49 |
; |
50 | 50 |
|
51 |
CREATE VIEW _specimens_06_count_of_unique_verb_subsp_taxa_with_author AS
|
|
51 |
-- _specimens_06_count_of_unique_verb_subsp_taxa_with_author
|
|
52 | 52 |
SELECT count(DISTINCT taxonlabel.taxonomicname) AS taxon_names_with_author |
53 | 53 |
FROM taxonlabel |
54 | 54 |
WHERE taxonlabel.source_id = (SELECT source_by_shortname(:datasource)) |
55 | 55 |
AND taxonlabel.taxonomicname IS NOT NULL |
56 | 56 |
; |
57 | 57 |
|
58 |
CREATE VIEW _specimens_07_list_of_verbatim_subspecific_taxa_with_author AS
|
|
58 |
-- _specimens_07_list_of_verbatim_subspecific_taxa_with_author
|
|
59 | 59 |
SELECT DISTINCT taxonlabel.taxonomicname AS taxon_name_with_author |
60 | 60 |
FROM taxonlabel |
61 | 61 |
WHERE taxonlabel.source_id = (SELECT source_by_shortname(:datasource)) |
62 | 62 |
AND taxonlabel.taxonomicname IS NOT NULL |
63 | 63 |
; |
64 | 64 |
|
65 |
CREATE VIEW _specimens_08_count_of_unique_verbatim_author_taxa_with_genus AS
|
|
65 |
-- _specimens_08_count_of_unique_verbatim_author_taxa_with_genus
|
|
66 | 66 |
SELECT count(DISTINCT taxonlabel.taxonomicname) AS taxon_names_with_author |
67 | 67 |
FROM taxonverbatim |
68 | 68 |
JOIN taxonlabel USING (taxonlabel_id) |
... | ... | |
70 | 70 |
AND genus IS NOT NULL |
71 | 71 |
; |
72 | 72 |
|
73 |
CREATE VIEW _specimens_09_list_of_unique_verbatim_author_taxa_with_genus AS
|
|
73 |
-- _specimens_09_list_of_unique_verbatim_author_taxa_with_genus
|
|
74 | 74 |
SELECT DISTINCT taxonlabel.taxonomicname AS taxon_name_with_author |
75 | 75 |
FROM taxonverbatim |
76 | 76 |
JOIN taxonlabel USING (taxonlabel_id) |
... | ... | |
78 | 78 |
AND genus IS NOT NULL |
79 | 79 |
; |
80 | 80 |
|
81 |
CREATE VIEW _specimens_10_count_number_of_records_by_institution AS
|
|
81 |
-- _specimens_10_count_number_of_records_by_institution
|
|
82 | 82 |
SELECT specimenreplicate.duplicate_institutions_sourcelist_id AS specimen_duplicate_institutions, |
83 | 83 |
count(*) AS records |
84 | 84 |
FROM specimenreplicate |
... | ... | |
86 | 86 |
GROUP BY specimen_duplicate_institutions |
87 | 87 |
; |
88 | 88 |
|
89 |
CREATE VIEW _specimens_11_list_of_three_standard_political_divisions AS
|
|
89 |
-- _specimens_11_list_of_three_standard_political_divisions
|
|
90 | 90 |
SELECT DISTINCT country, stateprovince, county |
91 | 91 |
FROM place |
92 | 92 |
WHERE place.source_id = (SELECT source_by_shortname(:datasource)) |
93 | 93 |
; |
94 |
COMMENT ON VIEW _specimens_01_count_of_total_records_specimens_in_source_db IS '
|
|
94 |
/*
|
|
95 | 95 |
Note: character set issues may cause mis-matches. This query is a good way to reveal character set issues, either in source db or in BIEN |
96 |
';
|
|
96 |
*/
|
|
97 | 97 |
|
98 |
CREATE VIEW _specimens_12_distinct_collector_name_collect_num_date_w_count AS
|
|
98 |
-- _specimens_12_distinct_collector_name_collect_num_date_w_count
|
|
99 | 99 |
SELECT |
100 | 100 |
(SELECT fullname FROM party WHERE party.party_id = collector_id) AS "collectorName" |
101 | 101 |
, collectionnumber AS "collectionNumber" |
... | ... | |
110 | 110 |
ORDER BY "collectorName", "collectionNumber", "dateCollected" |
111 | 111 |
; |
112 | 112 |
|
113 |
CREATE VIEW _specimens_13_count_of_all_verbatim_and_decimal_lat_long AS
|
|
113 |
-- _specimens_13_count_of_all_verbatim_and_decimal_lat_long
|
|
114 | 114 |
SELECT |
115 | 115 |
(SELECT count(*) AS count |
116 | 116 |
FROM coordinates |
... | ... | |
134 | 134 |
AS "decimalLongs" |
135 | 135 |
; |
136 | 136 |
|
137 |
CREATE VIEW _specimens_14_count_of_all_invalid_verbatim_lat_long AS
|
|
137 |
-- _specimens_14_count_of_all_invalid_verbatim_lat_long
|
|
138 | 138 |
SELECT |
139 | 139 |
(SELECT count(*) AS count |
140 | 140 |
FROM coordinates |
... | ... | |
146 | 146 |
AND (((coordinates.longitude_deg)::double precision > (180)::double precision) OR ((coordinates.longitude_deg)::double precision < ((-180))::double precision))) AS "badLongs" |
147 | 147 |
; |
148 | 148 |
|
149 |
CREATE VIEW _specimens_15_list_distinct_locality_descriptions AS
|
|
149 |
-- _specimens_15_list_distinct_locality_descriptions
|
|
150 | 150 |
SELECT DISTINCT locationnarrative AS "localityDescription" |
151 | 151 |
FROM location |
152 | 152 |
WHERE location.source_id = (SELECT source_by_shortname(:datasource)) |
153 | 153 |
AND locationnarrative IS NOT NULL |
154 | 154 |
; |
155 | 155 |
|
156 |
CREATE VIEW _specimens_16_list_distinct_specimen_descriptions AS
|
|
156 |
-- _specimens_16_list_distinct_specimen_descriptions
|
|
157 | 157 |
SELECT DISTINCT notes AS "specimenDescription" |
158 | 158 |
FROM aggregateoccurrence |
159 | 159 |
WHERE aggregateoccurrence.source_id = (SELECT source_by_shortname(:datasource)) |
Also available in: Unified diff
validation/aggregating/specimens/qualitative_validations_specimens.sql: removed DDL statements, using the steps at wiki.vegpath.org/Aggregating_validations_refactoring#remove-DDL-statements