Project

General

Profile

« Previous | Next » 

Revision 6779

schemas/vegbien.sql: analytical_*: Renamed institutionCode to datasource because this is actually the top-level datasource providing the record, not the institution storing the specimen

View differences:

vegbien.sql
911 911
GRANT SELECT ON TABLE analytical_aggregate TO bien_read;
912 912
GRANT SELECT ON TABLE analytical_aggregate_view TO bien_read;
913 913

  
914
ALTER TABLE analytical_aggregate ALTER COLUMN "institutionCode" SET NOT NULL;
914
ALTER TABLE analytical_aggregate ALTER COLUMN "datasource" SET NOT NULL;
915 915
ALTER TABLE analytical_aggregate ALTER COLUMN "locationName" SET NOT NULL;
916 916

  
917
CREATE INDEX ON analytical_aggregate ("institutionCode", "locationName", "dateCollected" );
917
CREATE INDEX ON analytical_aggregate ("datasource", "locationName", "dateCollected" );
918 918
$$;
919 919

  
920 920

  
......
931 931
GRANT SELECT ON TABLE analytical_stem TO bien_read;
932 932
GRANT SELECT ON TABLE analytical_stem_view TO bien_read;
933 933

  
934
ALTER TABLE analytical_stem ALTER COLUMN "institutionCode" SET NOT NULL;
934
ALTER TABLE analytical_stem ALTER COLUMN "datasource" SET NOT NULL;
935 935
ALTER TABLE analytical_stem ALTER COLUMN "locationName" SET NOT NULL;
936 936

  
937
CREATE INDEX ON analytical_stem ("institutionCode", "occurrenceID" );
938
CREATE INDEX ON analytical_stem ("institutionCode", "subInstitutionCode", "collectionCode", "catalogNumber" );
939
CREATE INDEX ON analytical_stem ("institutionCode", "projectID", "locationName", "dateCollected" );
937
CREATE INDEX ON analytical_stem ("datasource", "occurrenceID" );
938
CREATE INDEX ON analytical_stem ("datasource", "subInstitutionCode", "collectionCode", "catalogNumber" );
939
CREATE INDEX ON analytical_stem ("datasource", "projectID", "locationName", "dateCollected" );
940 940
$$;
941 941

  
942 942

  
......
1447 1447
--
1448 1448

  
1449 1449
CREATE TABLE analytical_aggregate (
1450
    "institutionCode" text NOT NULL,
1450
    datasource text NOT NULL,
1451 1451
    country text,
1452 1452
    "stateProvince" text,
1453 1453
    county text,
......
1486 1486
--
1487 1487

  
1488 1488
CREATE TABLE analytical_stem (
1489
    "institutionCode" text NOT NULL,
1489
    datasource text NOT NULL,
1490 1490
    "subInstitutionCode" text,
1491 1491
    "collectionCode" text,
1492 1492
    "catalogNumber" text,
......
1538 1538
--
1539 1539

  
1540 1540
CREATE VIEW analytical_aggregate_view AS
1541
    SELECT analytical_stem."institutionCode", analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid, analytical_stem."isNewWorld", analytical_stem."locationName", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."scientificName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis", sum(analytical_stem."coverPercent") AS "coverPercent", count(analytical_stem."diameterBreastHeight_cm") AS "individualCount", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((1)::double precision))) AS "individualCount_1cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((2.5)::double precision))) AS "individualCount_2_5cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((10)::double precision))) AS "individualCount_10cm_or_more" FROM analytical_stem GROUP BY analytical_stem."institutionCode", analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid, analytical_stem."isNewWorld", analytical_stem."locationName", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."scientificName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis";
1541
    SELECT analytical_stem.datasource, analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid, analytical_stem."isNewWorld", analytical_stem."locationName", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."scientificName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis", sum(analytical_stem."coverPercent") AS "coverPercent", count(analytical_stem."diameterBreastHeight_cm") AS "individualCount", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((1)::double precision))) AS "individualCount_1cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((2.5)::double precision))) AS "individualCount_2_5cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((10)::double precision))) AS "individualCount_10cm_or_more" FROM analytical_stem GROUP BY analytical_stem.datasource, analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid, analytical_stem."isNewWorld", analytical_stem."locationName", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."scientificName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis";
1542 1542

  
1543 1543

  
1544 1544
--
......
2343 2343
--
2344 2344

  
2345 2345
CREATE VIEW analytical_stem_view AS
2346
    SELECT source.shortname AS "institutionCode", sourcename.name AS "subInstitutionCode", specimenreplicate.collectioncode_dwc AS "collectionCode", specimenreplicate.catalognumber_dwc AS "catalogNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", canon_place.country, canon_place.stateprovince AS "stateProvince", datasource_place.county, coordinates.latitude_deg AS "decimalLatitude", coordinates.longitude_deg AS "decimalLongitude", coordinates.coordsaccuracy_m AS "coordinateUncertaintyInMeters", (canon_place.geovalid)::integer AS geovalid, ("newWorldCountries"."isNewWorld")::integer AS "isNewWorld", project.sourceaccessioncode AS "projectID", COALESCE(location.sourceaccessioncode, location.authorlocationcode) AS "locationName", location.elevation_m AS "elevationInMeters", _m2_to_ha(location.area_m2) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.obsstartdate, parent_event.obsstartdate, aggregateoccurrence.collectiondate) AS "dateCollected", family_higher_plant_group.higher_plant_group AS "higherPlantGroup", accepted_taxonverbatim.family, accepted_taxonverbatim.genus, ((accepted_taxonverbatim.genus || ' '::text) || accepted_taxonverbatim.specific_epithet) AS "speciesBinomial", COALESCE(accepted_taxonverbatim.taxonomicname, accepted_taxonverbatim.taxonname) AS "scientificName", accepted_taxonverbatim.author AS "scientificNameAuthorship", NULLIF(array_to_string(ARRAY[COALESCE(accepted_taxonverbatim.genus, accepted_taxonverbatim.family), COALESCE(accepted_taxonverbatim.specific_epithet, parsed_taxonverbatim.morphospecies)], ' '::text), ''::text) AS "speciesBinomialWithMorphospecies", NULLIF(array_to_string(ARRAY[accepted_taxonlabel.taxonomicname, parsed_taxonverbatim.morphospecies], ' '::text), ''::text) AS "scientificNameWithMorphospecies", ((threatened_taxonlabel.taxonlabel_id IS NOT NULL))::integer AS threatened, identifiedby.fullname AS "identifiedBy", taxonoccurrence.growthform AS "growthForm", (((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, location.iscultivated)))::integer AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis", collector.fullname AS "recordedBy", plantobservation.collectionnumber AS "recordNumber", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "coverPercent", _m_to_cm(stemobservation.diameterbreastheight_m) AS "diameterBreastHeight_cm", stemobservation.height_m, stemobservation.tag, stemobservation.xposition_m AS "organismX_m", stemobservation.yposition_m AS "organismY_m", taxonoccurrence.sourceaccessioncode AS "taxonOccurrenceID", taxonoccurrence.authortaxoncode AS "authorTaxonCode", plantobservation.sourceaccessioncode AS "individualID", stemobservation.authorstemcode AS "authorStemCode" FROM ((((((((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationevent USING (location_id)) LEFT JOIN location parent_location ON ((parent_location.location_id = location.parent_id))) LEFT JOIN locationplace ON ((locationplace.location_id = COALESCE(parent_location.location_id, location.location_id)))) LEFT JOIN place datasource_place USING (place_id)) LEFT JOIN place canon_place ON ((canon_place.place_id = datasource_place.canon_place_id))) LEFT JOIN coordinates ON ((coordinates.coordinates_id = canon_place.coordinates_id))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON (("newWorldCountries"."isoCode" = iso_code_gadm."2-digit iso code"))) LEFT JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN locationevent parent_event ON ((parent_event.locationevent_id = locationevent.parent_id))) LEFT JOIN project ON ((project.project_id = COALESCE(locationevent.project_id, parent_event.project_id)))) LEFT JOIN method ON ((method.method_id = COALESCE(locationevent.method_id, parent_event.method_id)))) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim datasource_taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel datasource_taxonlabel USING (taxonlabel_id)) LEFT JOIN taxonlabel parsed_taxonlabel ON ((parsed_taxonlabel.taxonlabel_id = datasource_taxonlabel.matched_label_id))) LEFT JOIN taxonverbatim parsed_taxonverbatim ON ((parsed_taxonverbatim.taxonlabel_id = parsed_taxonlabel.taxonlabel_id))) LEFT JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.canon_label_id))) LEFT JOIN taxonverbatim accepted_taxonverbatim ON ((accepted_taxonverbatim.taxonlabel_id = accepted_taxonlabel.taxonlabel_id))) LEFT JOIN threatened_taxonlabel ON ((threatened_taxonlabel.taxonlabel_id = accepted_taxonlabel.taxonlabel_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = accepted_taxonverbatim.family))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = accepted_taxonverbatim.family) AND (cultivated_family_locations.country = canon_place.country)))) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcename ON ((sourcename.sourcename_id = specimenreplicate.institution_id))) WHERE COALESCE(taxondetermination.iscurrent, true);
2346
    SELECT source.shortname AS datasource, sourcename.name AS "subInstitutionCode", specimenreplicate.collectioncode_dwc AS "collectionCode", specimenreplicate.catalognumber_dwc AS "catalogNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", canon_place.country, canon_place.stateprovince AS "stateProvince", datasource_place.county, coordinates.latitude_deg AS "decimalLatitude", coordinates.longitude_deg AS "decimalLongitude", coordinates.coordsaccuracy_m AS "coordinateUncertaintyInMeters", (canon_place.geovalid)::integer AS geovalid, ("newWorldCountries"."isNewWorld")::integer AS "isNewWorld", project.sourceaccessioncode AS "projectID", COALESCE(location.sourceaccessioncode, location.authorlocationcode) AS "locationName", location.elevation_m AS "elevationInMeters", _m2_to_ha(location.area_m2) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.obsstartdate, parent_event.obsstartdate, aggregateoccurrence.collectiondate) AS "dateCollected", family_higher_plant_group.higher_plant_group AS "higherPlantGroup", accepted_taxonverbatim.family, accepted_taxonverbatim.genus, ((accepted_taxonverbatim.genus || ' '::text) || accepted_taxonverbatim.specific_epithet) AS "speciesBinomial", COALESCE(accepted_taxonverbatim.taxonomicname, accepted_taxonverbatim.taxonname) AS "scientificName", accepted_taxonverbatim.author AS "scientificNameAuthorship", NULLIF(array_to_string(ARRAY[COALESCE(accepted_taxonverbatim.genus, accepted_taxonverbatim.family), COALESCE(accepted_taxonverbatim.specific_epithet, parsed_taxonverbatim.morphospecies)], ' '::text), ''::text) AS "speciesBinomialWithMorphospecies", NULLIF(array_to_string(ARRAY[accepted_taxonlabel.taxonomicname, parsed_taxonverbatim.morphospecies], ' '::text), ''::text) AS "scientificNameWithMorphospecies", ((threatened_taxonlabel.taxonlabel_id IS NOT NULL))::integer AS threatened, identifiedby.fullname AS "identifiedBy", taxonoccurrence.growthform AS "growthForm", (((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, location.iscultivated)))::integer AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis", collector.fullname AS "recordedBy", plantobservation.collectionnumber AS "recordNumber", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "coverPercent", _m_to_cm(stemobservation.diameterbreastheight_m) AS "diameterBreastHeight_cm", stemobservation.height_m, stemobservation.tag, stemobservation.xposition_m AS "organismX_m", stemobservation.yposition_m AS "organismY_m", taxonoccurrence.sourceaccessioncode AS "taxonOccurrenceID", taxonoccurrence.authortaxoncode AS "authorTaxonCode", plantobservation.sourceaccessioncode AS "individualID", stemobservation.authorstemcode AS "authorStemCode" FROM ((((((((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationevent USING (location_id)) LEFT JOIN location parent_location ON ((parent_location.location_id = location.parent_id))) LEFT JOIN locationplace ON ((locationplace.location_id = COALESCE(parent_location.location_id, location.location_id)))) LEFT JOIN place datasource_place USING (place_id)) LEFT JOIN place canon_place ON ((canon_place.place_id = datasource_place.canon_place_id))) LEFT JOIN coordinates ON ((coordinates.coordinates_id = canon_place.coordinates_id))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON (("newWorldCountries"."isoCode" = iso_code_gadm."2-digit iso code"))) LEFT JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN locationevent parent_event ON ((parent_event.locationevent_id = locationevent.parent_id))) LEFT JOIN project ON ((project.project_id = COALESCE(locationevent.project_id, parent_event.project_id)))) LEFT JOIN method ON ((method.method_id = COALESCE(locationevent.method_id, parent_event.method_id)))) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim datasource_taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel datasource_taxonlabel USING (taxonlabel_id)) LEFT JOIN taxonlabel parsed_taxonlabel ON ((parsed_taxonlabel.taxonlabel_id = datasource_taxonlabel.matched_label_id))) LEFT JOIN taxonverbatim parsed_taxonverbatim ON ((parsed_taxonverbatim.taxonlabel_id = parsed_taxonlabel.taxonlabel_id))) LEFT JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.canon_label_id))) LEFT JOIN taxonverbatim accepted_taxonverbatim ON ((accepted_taxonverbatim.taxonlabel_id = accepted_taxonlabel.taxonlabel_id))) LEFT JOIN threatened_taxonlabel ON ((threatened_taxonlabel.taxonlabel_id = accepted_taxonlabel.taxonlabel_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = accepted_taxonverbatim.family))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = accepted_taxonverbatim.family) AND (cultivated_family_locations.country = canon_place.country)))) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcename ON ((sourcename.sourcename_id = specimenreplicate.institution_id))) WHERE COALESCE(taxondetermination.iscurrent, true);
2347 2347

  
2348 2348

  
2349 2349
--
......
5965 5965

  
5966 5966

  
5967 5967
--
5968
-- Name: analytical_aggregate_institutionCode_locationName_dateColle_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5968
-- Name: analytical_aggregate_datasource_locationName_dateCollected_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5969 5969
--
5970 5970

  
5971
CREATE INDEX "analytical_aggregate_institutionCode_locationName_dateColle_idx" ON analytical_aggregate USING btree ("institutionCode", "locationName", "dateCollected");
5971
CREATE INDEX "analytical_aggregate_datasource_locationName_dateCollected_idx" ON analytical_aggregate USING btree (datasource, "locationName", "dateCollected");
5972 5972

  
5973 5973

  
5974 5974
--
5975
-- Name: analytical_stem_institutionCode_occurrenceID_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5975
-- Name: analytical_stem_datasource_occurrenceID_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5976 5976
--
5977 5977

  
5978
CREATE INDEX "analytical_stem_institutionCode_occurrenceID_idx" ON analytical_stem USING btree ("institutionCode", "occurrenceID");
5978
CREATE INDEX "analytical_stem_datasource_occurrenceID_idx" ON analytical_stem USING btree (datasource, "occurrenceID");
5979 5979

  
5980 5980

  
5981 5981
--
5982
-- Name: analytical_stem_institutionCode_projectID_locationName_date_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5982
-- Name: analytical_stem_datasource_projectID_locationName_dateColle_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5983 5983
--
5984 5984

  
5985
CREATE INDEX "analytical_stem_institutionCode_projectID_locationName_date_idx" ON analytical_stem USING btree ("institutionCode", "projectID", "locationName", "dateCollected");
5985
CREATE INDEX "analytical_stem_datasource_projectID_locationName_dateColle_idx" ON analytical_stem USING btree (datasource, "projectID", "locationName", "dateCollected");
5986 5986

  
5987 5987

  
5988 5988
--
5989
-- Name: analytical_stem_institutionCode_subInstitutionCode_collecti_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5989
-- Name: analytical_stem_datasource_subInstitutionCode_collectionCod_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5990 5990
--
5991 5991

  
5992
CREATE INDEX "analytical_stem_institutionCode_subInstitutionCode_collecti_idx" ON analytical_stem USING btree ("institutionCode", "subInstitutionCode", "collectionCode", "catalogNumber");
5992
CREATE INDEX "analytical_stem_datasource_subInstitutionCode_collectionCod_idx" ON analytical_stem USING btree (datasource, "subInstitutionCode", "collectionCode", "catalogNumber");
5993 5993

  
5994 5994

  
5995 5995
--

Also available in: Unified diff