Revision 5626
Added by Aaron Marcuse-Kubitza about 12 years ago
schemas/vegbien.my.sql | ||
---|---|---|
194 | 194 |
|
195 | 195 |
|
196 | 196 |
-- |
197 |
-- Name: taxonlabel_2_propagate_accepted_label_id(); Type: FUNCTION; Schema: public; Owner: -
|
|
197 |
-- Name: taxonlabel_2_propagate_canon_label_id(); Type: FUNCTION; Schema: public; Owner: -
|
|
198 | 198 |
-- |
199 | 199 |
|
200 | 200 |
|
... | ... | |
222 | 222 |
concept_reference_id int(11), |
223 | 223 |
creationdate date, |
224 | 224 |
taxonstatus text, |
225 |
accepted_label_id int(11),
|
|
225 |
canon_label_id int(11),
|
|
226 | 226 |
matched_label_id int(11), |
227 | 227 |
matched_label_fit_fraction double precision, |
228 | 228 |
parent_id int(11), |
... | ... | |
278 | 278 |
|
279 | 279 |
|
280 | 280 |
-- |
281 |
-- Name: COLUMN taxonlabel.accepted_label_id; Type: COMMENT; Schema: public; Owner: -
|
|
281 |
-- Name: COLUMN taxonlabel.canon_label_id; Type: COMMENT; Schema: public; Owner: -
|
|
282 | 282 |
-- |
283 | 283 |
|
284 | 284 |
|
... | ... | |
1094 | 1094 |
-- |
1095 | 1095 |
|
1096 | 1096 |
CREATE VIEW analytical_db_view AS |
1097 |
SELECT datasource.organizationname AS `dataSourceName`, accepted_taxonlabel.family, accepted_taxonlabel.genus, accepted_taxonlabel.species, COALESCE(accepted_taxonlabel.taxonomicnamewithauthor, accepted_taxonlabel.taxonomicname) AS taxon, accepted_taxonlabel.author AS `taxonAuthor`, accepted_taxonlabel.taxonepithet AS `taxonMorphospecies`, placepath.country, placepath.stateprovince AS `stateProvince`, placepath.county AS `countyParish`, taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS `collectionNumber`, array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], CAST(' ' AS text)) AS `identifiedBy`, aggregateoccurrence.collectiondate AS `observationDate`, location.authorlocationcode AS `plotCode`, functions._m2_to_ha(location.area_m2) AS `plotAreaHa`, method.name AS `plotMethod`, locationcoords.latitude_deg AS latitude, locationcoords.longitude_deg AS longitude, location.elevation_m, taxonoccurrence.iscultivated AS `isCultivated`, taxonoccurrence.cultivatedbasis AS `isCultivatedReason`, _fraction_to_percent(aggregateoccurrence.cover_fraction) AS `pctCover` FROM ((((((((((((((location JOIN party datasource ON (((datasource.party_id = location.creator_id) AND (datasource.organizationname IS NOT NULL)))) LEFT JOIN locationcoords USING (location_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN placepath USING (placepath_id)) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonlabel datasource_taxonlabel USING (taxonlabel_id)) JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.accepted_label_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
|
|
1097 |
SELECT datasource.organizationname AS `dataSourceName`, accepted_taxonlabel.family, accepted_taxonlabel.genus, accepted_taxonlabel.species, COALESCE(accepted_taxonlabel.taxonomicnamewithauthor, accepted_taxonlabel.taxonomicname) AS taxon, accepted_taxonlabel.author AS `taxonAuthor`, accepted_taxonlabel.taxonepithet AS `taxonMorphospecies`, placepath.country, placepath.stateprovince AS `stateProvince`, placepath.county AS `countyParish`, taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS `collectionNumber`, array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], CAST(' ' AS text)) AS `identifiedBy`, aggregateoccurrence.collectiondate AS `observationDate`, location.authorlocationcode AS `plotCode`, functions._m2_to_ha(location.area_m2) AS `plotAreaHa`, method.name AS `plotMethod`, locationcoords.latitude_deg AS latitude, locationcoords.longitude_deg AS longitude, location.elevation_m, taxonoccurrence.iscultivated AS `isCultivated`, taxonoccurrence.cultivatedbasis AS `isCultivatedReason`, _fraction_to_percent(aggregateoccurrence.cover_fraction) AS `pctCover` FROM ((((((((((((((location JOIN party datasource ON (((datasource.party_id = location.creator_id) AND (datasource.organizationname IS NOT NULL)))) LEFT JOIN locationcoords USING (location_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN placepath USING (placepath_id)) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonlabel datasource_taxonlabel USING (taxonlabel_id)) JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.canon_label_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
|
|
1098 | 1098 |
|
1099 | 1099 |
|
1100 | 1100 |
-- |
... | ... | |
4118 | 4118 |
|
4119 | 4119 |
|
4120 | 4120 |
-- |
4121 |
-- Name: taxonlabel_2_propagate_accepted_label_id; Type: TRIGGER; Schema: public; Owner: -
|
|
4121 |
-- Name: taxonlabel_2_propagate_canon_label_id; Type: TRIGGER; Schema: public; Owner: -
|
|
4122 | 4122 |
-- |
4123 | 4123 |
|
4124 | 4124 |
|
... | ... | |
4936 | 4936 |
|
4937 | 4937 |
|
4938 | 4938 |
-- |
4939 |
-- Name: taxonlabel_accepted_label_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
4939 |
-- Name: taxonlabel_canon_label_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
4940 | 4940 |
-- |
4941 | 4941 |
|
4942 | 4942 |
ALTER TABLE taxonlabel |
4943 |
ADD CONSTRAINT taxonlabel_accepted_label_id_fkey FOREIGN KEY (accepted_label_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
4943 |
ADD CONSTRAINT taxonlabel_canon_label_id_fkey FOREIGN KEY (canon_label_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
4944 | 4944 |
|
4945 | 4945 |
|
4946 | 4946 |
-- |
schemas/vegbien.sql | ||
---|---|---|
481 | 481 |
|
482 | 482 |
|
483 | 483 |
-- |
484 |
-- Name: taxonlabel_2_propagate_accepted_label_id(); Type: FUNCTION; Schema: public; Owner: -
|
|
484 |
-- Name: taxonlabel_2_propagate_canon_label_id(); Type: FUNCTION; Schema: public; Owner: -
|
|
485 | 485 |
-- |
486 | 486 |
|
487 |
CREATE FUNCTION taxonlabel_2_propagate_accepted_label_id() RETURNS trigger
|
|
487 |
CREATE FUNCTION taxonlabel_2_propagate_canon_label_id() RETURNS trigger
|
|
488 | 488 |
LANGUAGE plpgsql |
489 | 489 |
AS $$ |
490 | 490 |
BEGIN |
491 | 491 |
IF new.matched_label_id IS NOT NULL THEN |
492 | 492 |
IF new.matched_label_id = new.taxonlabel_id THEN -- self-reference |
493 |
new.accepted_label_id = new.taxonlabel_id;-- make self-reference
|
|
493 |
new.canon_label_id = new.taxonlabel_id;-- make self-reference
|
|
494 | 494 |
ELSE -- propagate from matched label |
495 |
new.accepted_label_id = (
|
|
496 |
SELECT accepted_label_id
|
|
495 |
new.canon_label_id = (
|
|
496 |
SELECT canon_label_id
|
|
497 | 497 |
FROM taxonlabel |
498 | 498 |
WHERE taxonlabel_id = new.matched_label_id |
499 | 499 |
); |
500 | 500 |
END IF; |
501 | 501 |
|
502 |
-- Update accepted_label_id on labels that resolve to this label
|
|
502 |
-- Update canon_label_id on labels that resolve to this label
|
|
503 | 503 |
UPDATE taxonlabel |
504 |
SET accepted_label_id = new.accepted_label_id
|
|
504 |
SET canon_label_id = new.canon_label_id
|
|
505 | 505 |
WHERE matched_label_id = new.taxonlabel_id |
506 | 506 |
AND taxonlabel_id != new.taxonlabel_id -- avoid infinite recursion |
507 | 507 |
; |
... | ... | |
540 | 540 |
concept_reference_id integer, |
541 | 541 |
creationdate date, |
542 | 542 |
taxonstatus taxonomic_status, |
543 |
accepted_label_id integer,
|
|
543 |
canon_label_id integer,
|
|
544 | 544 |
matched_label_id integer, |
545 | 545 |
matched_label_fit_fraction double precision, |
546 | 546 |
parent_id integer, |
... | ... | |
608 | 608 |
|
609 | 609 |
|
610 | 610 |
-- |
611 |
-- Name: COLUMN taxonlabel.accepted_label_id; Type: COMMENT; Schema: public; Owner: -
|
|
611 |
-- Name: COLUMN taxonlabel.canon_label_id; Type: COMMENT; Schema: public; Owner: -
|
|
612 | 612 |
-- |
613 | 613 |
|
614 |
COMMENT ON COLUMN taxonlabel.accepted_label_id IS 'The accepted synonym of the taxonlabel.';
|
|
614 |
COMMENT ON COLUMN taxonlabel.canon_label_id IS 'The canonical taxonlabel for this taxonlabel.';
|
|
615 | 615 |
|
616 | 616 |
|
617 | 617 |
-- |
... | ... | |
1554 | 1554 |
-- |
1555 | 1555 |
|
1556 | 1556 |
CREATE VIEW analytical_db_view AS |
1557 |
SELECT datasource.organizationname AS "dataSourceName", accepted_taxonlabel.family, accepted_taxonlabel.genus, accepted_taxonlabel.species, COALESCE(accepted_taxonlabel.taxonomicnamewithauthor, accepted_taxonlabel.taxonomicname) AS taxon, accepted_taxonlabel.author AS "taxonAuthor", accepted_taxonlabel.taxonepithet AS "taxonMorphospecies", placepath.country, placepath.stateprovince AS "stateProvince", placepath.county AS "countyParish", taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS "collectionNumber", array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text) AS "identifiedBy", aggregateoccurrence.collectiondate AS "observationDate", location.authorlocationcode AS "plotCode", functions._m2_to_ha(location.area_m2) AS "plotAreaHa", method.name AS "plotMethod", locationcoords.latitude_deg AS latitude, locationcoords.longitude_deg AS longitude, location.elevation_m, taxonoccurrence.iscultivated AS "isCultivated", taxonoccurrence.cultivatedbasis AS "isCultivatedReason", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "pctCover" FROM ((((((((((((((location JOIN party datasource ON (((datasource.party_id = location.creator_id) AND (datasource.organizationname IS NOT NULL)))) LEFT JOIN locationcoords USING (location_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN placepath USING (placepath_id)) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonlabel datasource_taxonlabel USING (taxonlabel_id)) JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.accepted_label_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
|
|
1557 |
SELECT datasource.organizationname AS "dataSourceName", accepted_taxonlabel.family, accepted_taxonlabel.genus, accepted_taxonlabel.species, COALESCE(accepted_taxonlabel.taxonomicnamewithauthor, accepted_taxonlabel.taxonomicname) AS taxon, accepted_taxonlabel.author AS "taxonAuthor", accepted_taxonlabel.taxonepithet AS "taxonMorphospecies", placepath.country, placepath.stateprovince AS "stateProvince", placepath.county AS "countyParish", taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS "collectionNumber", array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text) AS "identifiedBy", aggregateoccurrence.collectiondate AS "observationDate", location.authorlocationcode AS "plotCode", functions._m2_to_ha(location.area_m2) AS "plotAreaHa", method.name AS "plotMethod", locationcoords.latitude_deg AS latitude, locationcoords.longitude_deg AS longitude, location.elevation_m, taxonoccurrence.iscultivated AS "isCultivated", taxonoccurrence.cultivatedbasis AS "isCultivatedReason", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "pctCover" FROM ((((((((((((((location JOIN party datasource ON (((datasource.party_id = location.creator_id) AND (datasource.organizationname IS NOT NULL)))) LEFT JOIN locationcoords USING (location_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN placepath USING (placepath_id)) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonlabel datasource_taxonlabel USING (taxonlabel_id)) JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.canon_label_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
|
|
1558 | 1558 |
|
1559 | 1559 |
|
1560 | 1560 |
-- |
... | ... | |
4867 | 4867 |
|
4868 | 4868 |
|
4869 | 4869 |
-- |
4870 |
-- Name: taxonlabel_2_propagate_accepted_label_id; Type: TRIGGER; Schema: public; Owner: -
|
|
4870 |
-- Name: taxonlabel_2_propagate_canon_label_id; Type: TRIGGER; Schema: public; Owner: -
|
|
4871 | 4871 |
-- |
4872 | 4872 |
|
4873 |
CREATE TRIGGER taxonlabel_2_propagate_accepted_label_id BEFORE INSERT OR UPDATE ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_2_propagate_accepted_label_id();
|
|
4873 |
CREATE TRIGGER taxonlabel_2_propagate_canon_label_id BEFORE INSERT OR UPDATE ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_2_propagate_canon_label_id();
|
|
4874 | 4874 |
|
4875 | 4875 |
|
4876 | 4876 |
-- |
... | ... | |
5719 | 5719 |
|
5720 | 5720 |
|
5721 | 5721 |
-- |
5722 |
-- Name: taxonlabel_accepted_label_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
5722 |
-- Name: taxonlabel_canon_label_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
5723 | 5723 |
-- |
5724 | 5724 |
|
5725 | 5725 |
ALTER TABLE ONLY taxonlabel |
5726 |
ADD CONSTRAINT taxonlabel_accepted_label_id_fkey FOREIGN KEY (accepted_label_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
5726 |
ADD CONSTRAINT taxonlabel_canon_label_id_fkey FOREIGN KEY (canon_label_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
5727 | 5727 |
|
5728 | 5728 |
|
5729 | 5729 |
-- |
Also available in: Unified diff
taxonlabel: Renamed accepted_label_id to canon_label_id to allow any taxonlabel to be the canonical taxonlabel for this taxonlabel, whether or not its status is accepted