Project

General

Profile

« Previous | Next » 

Revision 13062

validation/aggregating/specimens/qualitative_validations_specimens.sql: parameterize queries by datasource

View differences:

trunk/validation/aggregating/specimens/qualitative_validations_specimens.sql
17 17
CREATE VIEW _specimens_01_count_of_total_records_specimens_in_source_db AS
18 18
SELECT count(*) AS "totalSpecimenRecords"
19 19
FROM taxonoccurrence
20
WHERE taxonoccurrence.source_id = (SELECT source_by_shortname('NY'))
20
WHERE taxonoccurrence.source_id = (SELECT source_by_shortname(:datasource))
21 21
;
22 22

  
23 23
CREATE VIEW _specimens_02_count_of_unique_verbatim_families AS
24 24
SELECT count(DISTINCT family) AS families
25 25
FROM taxonverbatim
26
WHERE taxonverbatim.source_id = (SELECT source_by_shortname('NY'))
26
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource))
27 27
AND family IS NOT NULL
28 28
;
29 29

  
30 30
CREATE VIEW _specimens_03_list_of_verbatim_families AS
31 31
SELECT DISTINCT family
32 32
FROM taxonverbatim
33
WHERE taxonverbatim.source_id = (SELECT source_by_shortname('NY'))
33
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource))
34 34
AND family IS NOT NULL
35 35
;
36 36

  
37 37
CREATE VIEW _specimens_04_count_of_species_binomials AS
38 38
SELECT count(DISTINCT concat_ws(' '::text, genus, specific_epithet)) AS species_binomials
39 39
FROM taxonverbatim
40
WHERE taxonverbatim.source_id = (SELECT source_by_shortname('NY'))
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 44
CREATE VIEW _specimens_05_list_of_species_binomials AS
45 45
SELECT DISTINCT concat_ws(' '::text, genus, specific_epithet) AS species_binomial
46 46
FROM taxonverbatim
47
WHERE taxonverbatim.source_id = (SELECT source_by_shortname('NY'))
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 51
CREATE VIEW _specimens_06_count_of_unique_verb_subsp_taxa_with_author AS
52 52
SELECT count(DISTINCT taxonlabel.taxonomicname) AS taxon_names_with_author
53 53
FROM taxonlabel
54
WHERE taxonlabel.source_id = (SELECT source_by_shortname('NY'))
54
WHERE taxonlabel.source_id = (SELECT source_by_shortname(:datasource))
55 55
AND taxonlabel.taxonomicname IS NOT NULL
56 56
;
57 57

  
58 58
CREATE VIEW _specimens_07_list_of_verbatim_subspecific_taxa_with_author AS
59 59
SELECT DISTINCT taxonlabel.taxonomicname AS taxon_name_with_author
60 60
FROM taxonlabel
61
WHERE taxonlabel.source_id = (SELECT source_by_shortname('NY'))
61
WHERE taxonlabel.source_id = (SELECT source_by_shortname(:datasource))
62 62
AND taxonlabel.taxonomicname IS NOT NULL
63 63
;
64 64

  
......
66 66
SELECT count(DISTINCT taxonlabel.taxonomicname) AS taxon_names_with_author
67 67
FROM taxonverbatim
68 68
JOIN taxonlabel USING (taxonlabel_id)
69
WHERE taxonverbatim.source_id = (SELECT source_by_shortname('NY'))
69
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource))
70 70
AND genus IS NOT NULL
71 71
;
72 72

  
......
74 74
SELECT DISTINCT taxonlabel.taxonomicname AS taxon_name_with_author
75 75
FROM taxonverbatim
76 76
JOIN taxonlabel USING (taxonlabel_id)
77
WHERE taxonverbatim.source_id = (SELECT source_by_shortname('NY'))
77
WHERE taxonverbatim.source_id = (SELECT source_by_shortname(:datasource))
78 78
AND genus IS NOT NULL
79 79
;
80 80

  
......
82 82
SELECT specimenreplicate.duplicate_institutions_sourcelist_id AS specimen_duplicate_institutions,
83 83
count(*) AS records
84 84
FROM specimenreplicate
85
WHERE specimenreplicate.source_id = (SELECT source_by_shortname('NY'))
85
WHERE specimenreplicate.source_id = (SELECT source_by_shortname(:datasource))
86 86
GROUP BY specimen_duplicate_institutions
87 87
;
88 88

  
89 89
CREATE VIEW _specimens_11_list_of_three_standard_political_divisions AS
90 90
SELECT DISTINCT country, stateprovince, county
91 91
FROM place
92
WHERE place.source_id = (SELECT source_by_shortname('NY'))
92
WHERE place.source_id = (SELECT source_by_shortname(:datasource))
93 93
;
94 94
COMMENT ON VIEW _specimens_01_count_of_total_records_specimens_in_source_db IS '
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
......
105 105
JOIN aggregateoccurrence USING (taxonoccurrence_id)
106 106
JOIN plantobservation USING (aggregateoccurrence_id)
107 107
JOIN specimenreplicate USING (plantobservation_id)
108
WHERE taxonoccurrence.source_id = (SELECT source_by_shortname('NY'))
108
WHERE taxonoccurrence.source_id = (SELECT source_by_shortname(:datasource))
109 109
GROUP BY "collectorName", "collectionNumber", "dateCollected"
110 110
ORDER BY "collectorName", "collectionNumber", "dateCollected"
111 111
;
......
114 114
SELECT
115 115
   (SELECT count(*) AS count
116 116
	FROM coordinates
117
	WHERE coordinates.source_id = (SELECT source_by_shortname('NY'))
117
	WHERE coordinates.source_id = (SELECT source_by_shortname(:datasource))
118 118
	AND (verbatimlatitude IS NOT NULL OR latitude_deg IS NOT NULL))
119 119
	AS "allLats"
120 120
,  (SELECT count(*) AS count
121 121
	FROM coordinates
122
	WHERE coordinates.source_id = (SELECT source_by_shortname('NY'))
122
	WHERE coordinates.source_id = (SELECT source_by_shortname(:datasource))
123 123
	AND (latitude_deg IS NOT NULL))
124 124
	AS "decimalLats"
125 125
,  (SELECT count(*) AS count
126 126
	FROM coordinates
127
	WHERE coordinates.source_id = (SELECT source_by_shortname('NY'))
127
	WHERE coordinates.source_id = (SELECT source_by_shortname(:datasource))
128 128
	AND (verbatimlongitude IS NOT NULL OR longitude_deg IS NOT NULL))
129 129
	AS "allLongs"
130 130
,  (SELECT count(*) AS count
131 131
	FROM coordinates
132
	WHERE coordinates.source_id = (SELECT source_by_shortname('NY'))
132
	WHERE coordinates.source_id = (SELECT source_by_shortname(:datasource))
133 133
	AND (longitude_deg IS NOT NULL))
134 134
	AS "decimalLongs"
135 135
;
......
138 138
SELECT
139 139
  (SELECT count(*) AS count
140 140
	FROM coordinates
141
	WHERE coordinates.source_id = (SELECT source_by_shortname('NY'))
141
	WHERE coordinates.source_id = (SELECT source_by_shortname(:datasource))
142 142
	AND (((coordinates.latitude_deg)::double precision > (90)::double precision) OR ((coordinates.latitude_deg)::double precision < ((-90))::double precision))) AS "badLats"
143 143
, (SELECT count(*) AS count
144 144
	FROM coordinates
145
	WHERE coordinates.source_id = (SELECT source_by_shortname('NY'))
145
	WHERE coordinates.source_id = (SELECT source_by_shortname(:datasource))
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 149
CREATE VIEW _specimens_15_list_distinct_locality_descriptions AS
150 150
SELECT DISTINCT locationnarrative AS "localityDescription"
151 151
FROM location
152
WHERE location.source_id = (SELECT source_by_shortname('NY'))
152
WHERE location.source_id = (SELECT source_by_shortname(:datasource))
153 153
AND locationnarrative IS NOT NULL
154 154
;
155 155

  
156 156
CREATE VIEW _specimens_16_list_distinct_specimen_descriptions AS
157 157
SELECT DISTINCT notes AS "specimenDescription"
158 158
FROM aggregateoccurrence
159
WHERE aggregateoccurrence.source_id = (SELECT source_by_shortname('NY'))
159
WHERE aggregateoccurrence.source_id = (SELECT source_by_shortname(:datasource))
160 160
AND notes IS NOT NULL
161 161
;

Also available in: Unified diff