Revision 11623
Added by Aaron Marcuse-Kubitza about 11 years ago
schemas/vegbien.sql | ||
---|---|---|
2760 | 2760 |
-- |
2761 | 2761 |
|
2762 | 2762 |
CREATE VIEW analytical_stem_view AS |
2763 |
SELECT "plot.**".datasource, "plot.**".country, "plot.**"."stateProvince", "plot.**".county, "plot.**".locality, "plot.**"."decimalLatitude", "plot.**"."decimalLongitude", "plot.**"."coordinateUncertaintyInMeters", "plot.**"."coordinateSource_bien", "plot.**"."georeferenceProtocol_bien", "plot.**".geovalid_bien, "plot.**"."isNewWorld_bien", "plot.**"."projectID", "plot.**"."locationID", "plot.**"."locationName", "plot.**".subplot, "plot.**".location__cultivated__bien, "plot.**".locationevent__pkey, "plot.**"."eventDate", "plot.**"."elevationInMeters", "plot.**"."slopeAspect", "plot.**"."slopeGradient", "plot.**"."plotArea_ha", "plot.**"."samplingProtocol", "plot.**"."temperature_C", "plot.**".precipitation_m, "plot.**".stratum__name, "plot.**".communities, "plot.**".plot__collectors, sourcelist.name AS "specimenHolderInstitutions", specimenreplicate.collectioncode_dwc AS collection, specimenreplicate.catalognumber_dwc AS "accessionNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", collector.fullname AS "recordedBy", plantobservation.authorplantcode AS "recordNumber", COALESCE(aggregateoccurrence.collectiondate, "plot.**"."eventDate") AS "dateCollected", taxonverbatim.family AS family_verbatim, COALESCE(taxonverbatim.taxonomicname, NULLIF(pg_catalog.concat_ws(' '::text, taxonverbatim.taxonname, taxonverbatim.author), ''::text), taxonlabel.taxonomicname) AS "scientificName_verbatim", identifiedby.fullname AS "identifiedBy", taxondetermination.determinationdate AS "dateIdentified", taxondetermination.notes AS "identificationRemarks", "ScrubbedTaxon"."matchedFamily" AS family_matched, "ScrubbedTaxon"."matchedTaxonName" AS "taxonName_matched", "ScrubbedTaxon"."matchedScientificNameAuthorship" AS "scientificNameAuthorship_matched", family_higher_plant_group.higher_plant_group AS "higherPlantGroup_bien", COALESCE("ScrubbedTaxon"."acceptedFamily", "ScrubbedTaxon"."matchedFamily") AS scrubbed_family, COALESCE("ScrubbedTaxon"."acceptedGenus", "ScrubbedTaxon"."matchedGenus") AS scrubbed_genus, COALESCE(COALESCE(NULLIF(pg_catalog.concat_ws(' '::text, COALESCE("ScrubbedTaxon"."acceptedGenus", "ScrubbedTaxon"."acceptedFamily"), "ScrubbedTaxon"."acceptedSpecificEpithet", "ScrubbedTaxon"."morphospeciesSuffix"), ''::text), "ScrubbedTaxon"."acceptedTaxonName"), COALESCE(NULLIF(pg_catalog.concat_ws(' '::text, COALESCE("ScrubbedTaxon"."matchedGenus", "ScrubbedTaxon"."matchedFamily"), "ScrubbedTaxon"."matchedSpecificEpithet", "ScrubbedTaxon"."morphospeciesSuffix"), ''::text), "ScrubbedTaxon"."matchedTaxonName"), "ScrubbedTaxon"."concatenatedScientificName") AS scrubbed_morphospecies_binomial, "ScrubbedTaxon"."acceptedTaxonName" AS scrubbed_taxon_name_no_author, "ScrubbedTaxon"."acceptedScientificNameAuthorship" AS scrubbed_author, taxonoccurrence.growthform AS "growthForm", plantobservation.reproductivecondition AS "reproductiveCondition", ((threatened_taxonlabel.taxonlabel_id IS NOT NULL))::integer AS threatened_bien, (((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, "plot.**".location__cultivated__bien)))::integer AS cultivated_bien, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN ("plot.**".location__cultivated__bien IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis_bien", aggregateoccurrence.notes AS "occurrenceRemarks", _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", aggregateoccurrence.sourceaccessioncode AS "aggregateOrganismObservationID", plantobservation.sourceaccessioncode AS "individualObservationID", plantobservation.authorplantcode AS "individualCode", aggregateoccurrence.count AS "individualCount", stemobservation.authorstemcode AS "authorStemCode" FROM ((((((((((((((("plot.**" LEFT JOIN taxonoccurrence ON ((taxonoccurrence.locationevent_id = "plot.**".locationevent__pkey))) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcelist ON ((sourcelist.sourcelist_id = specimenreplicate.institution_id))) LEFT JOIN taxondetermination ON (((taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id) AND taxondetermination.iscurrent))) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel USING (taxonlabel_id)) LEFT JOIN "TNRS"."ScrubbedTaxon" ON (("ScrubbedTaxon"."concatenatedScientificName" = taxonlabel.taxonomicname))) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = "ScrubbedTaxon"."acceptedFamily"))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = "ScrubbedTaxon"."acceptedFamily") AND (cultivated_family_locations.country = "plot.**".country)))) LEFT JOIN threatened_taxonlabel USING (taxonlabel_id));
|
|
2763 |
SELECT "plot.**".datasource, "plot.**".country, "plot.**"."stateProvince", "plot.**".county, "plot.**".locality, "plot.**"."decimalLatitude", "plot.**"."decimalLongitude", "plot.**"."coordinateUncertaintyInMeters", "plot.**"."coordinateSource_bien", "plot.**"."georeferenceProtocol_bien", "plot.**".geovalid_bien, "plot.**"."isNewWorld_bien", "plot.**"."projectID", "plot.**"."locationID", "plot.**"."locationName", "plot.**".subplot, "plot.**".location__cultivated__bien, "plot.**".locationevent__pkey, "plot.**"."eventDate", "plot.**"."elevationInMeters", "plot.**"."slopeAspect", "plot.**"."slopeGradient", "plot.**"."plotArea_ha", "plot.**"."samplingProtocol", "plot.**"."temperature_C", "plot.**".precipitation_m, "plot.**".stratum__name, "plot.**".communities, "plot.**".plot__collectors, sourcelist.name AS "specimenHolderInstitutions", specimenreplicate.collectioncode_dwc AS collection, specimenreplicate.catalognumber_dwc AS "accessionNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", collector.fullname AS "recordedBy", plantobservation.authorplantcode AS "recordNumber", COALESCE(aggregateoccurrence.collectiondate, "plot.**"."eventDate") AS "dateCollected", taxonverbatim.family AS family_verbatim, COALESCE(taxonverbatim.taxonomicname, NULLIF(pg_catalog.concat_ws(' '::text, taxonverbatim.taxonname, taxonverbatim.author), ''::text), taxonlabel.taxonomicname) AS "scientificName_verbatim", identifiedby.fullname AS "identifiedBy", taxondetermination.determinationdate AS "dateIdentified", taxondetermination.notes AS "identificationRemarks", "ScrubbedTaxon"."matchedFamily" AS family_matched, "ScrubbedTaxon"."matchedTaxonName" AS "taxonName_matched", "ScrubbedTaxon"."matchedScientificNameAuthorship" AS "scientificNameAuthorship_matched", family_higher_plant_group.higher_plant_group AS "higherPlantGroup_bien", COALESCE("ScrubbedTaxon"."acceptedFamily", "ScrubbedTaxon"."matchedFamily") AS scrubbed_family, COALESCE("ScrubbedTaxon"."acceptedGenus", "ScrubbedTaxon"."matchedGenus") AS scrubbed_genus, COALESCE(COALESCE(NULLIF(pg_catalog.concat_ws(' '::text, COALESCE("ScrubbedTaxon"."acceptedGenus", "ScrubbedTaxon"."acceptedFamily"), "ScrubbedTaxon"."acceptedSpecificEpithet", "ScrubbedTaxon"."morphospeciesSuffix"), ''::text), "ScrubbedTaxon"."acceptedTaxonName"), COALESCE(NULLIF(pg_catalog.concat_ws(' '::text, COALESCE("ScrubbedTaxon"."matchedGenus", "ScrubbedTaxon"."matchedFamily"), "ScrubbedTaxon"."matchedSpecificEpithet", "ScrubbedTaxon"."morphospeciesSuffix"), ''::text), "ScrubbedTaxon"."matchedTaxonName"), "ScrubbedTaxon"."concatenatedScientificName") AS scrubbed_morphospecies_binomial, COALESCE("ScrubbedTaxon"."acceptedTaxonName", "ScrubbedTaxon"."matchedTaxonName") AS scrubbed_taxon_name_no_author, COALESCE("ScrubbedTaxon"."acceptedScientificNameAuthorship", "ScrubbedTaxon"."matchedScientificNameAuthorship") AS scrubbed_author, taxonoccurrence.growthform AS "growthForm", plantobservation.reproductivecondition AS "reproductiveCondition", ((threatened_taxonlabel.taxonlabel_id IS NOT NULL))::integer AS threatened_bien, (((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, "plot.**".location__cultivated__bien)))::integer AS cultivated_bien, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN ("plot.**".location__cultivated__bien IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis_bien", aggregateoccurrence.notes AS "occurrenceRemarks", _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", aggregateoccurrence.sourceaccessioncode AS "aggregateOrganismObservationID", plantobservation.sourceaccessioncode AS "individualObservationID", plantobservation.authorplantcode AS "individualCode", aggregateoccurrence.count AS "individualCount", stemobservation.authorstemcode AS "authorStemCode" FROM ((((((((((((((("plot.**" LEFT JOIN taxonoccurrence ON ((taxonoccurrence.locationevent_id = "plot.**".locationevent__pkey))) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcelist ON ((sourcelist.sourcelist_id = specimenreplicate.institution_id))) LEFT JOIN taxondetermination ON (((taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id) AND taxondetermination.iscurrent))) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel USING (taxonlabel_id)) LEFT JOIN "TNRS"."ScrubbedTaxon" ON (("ScrubbedTaxon"."concatenatedScientificName" = taxonlabel.taxonomicname))) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = "ScrubbedTaxon"."acceptedFamily"))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = "ScrubbedTaxon"."acceptedFamily") AND (cultivated_family_locations.country = "plot.**".country)))) LEFT JOIN threatened_taxonlabel USING (taxonlabel_id));
|
|
2764 | 2764 |
|
2765 | 2765 |
|
2766 | 2766 |
-- |
Also available in: Unified diff
bugfix: schemas/vegbien.sql: analytical_stem_view: scrubbed_taxon_name_no_author, scrubbed_author: need to COALESCE these to the matched* when no accepted* is available