Project

General

Profile

« Previous | Next » 

Revision 6435

schemas/vegbien.sql: analytical_stem_view: cultivated: Also set if family/country combination found in cultivated_family_locations

View differences:

schemas/vegbien.my.sql
800 800

  
801 801

  
802 802
--
803
-- Name: cultivated_family_locations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
804
--
805

  
806
CREATE TABLE cultivated_family_locations (
807
    family varchar(255) NOT NULL,
808
    country varchar(255) NOT NULL
809
);
810

  
811

  
812
--
803 813
-- Name: family_higher_plant_group; Type: TABLE; Schema: public; Owner: -; Tablespace: 
804 814
--
805 815

  
......
1869 1879

  
1870 1880

  
1871 1881
--
1872
-- Name: cultivated_family_locations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1873
--
1874

  
1875
CREATE TABLE cultivated_family_locations (
1876
    family varchar(255) NOT NULL,
1877
    country varchar(255) NOT NULL
1878
);
1879

  
1880

  
1881
--
1882 1882
-- Name: dba_preassignacccode_dba_requestnumber_seq; Type: SEQUENCE; Schema: public; Owner: -
1883 1883
--
1884 1884

  
......
6467 6467

  
6468 6468

  
6469 6469
--
6470
-- Name: cultivated_family_locations; Type: ACL; Schema: public; Owner: -
6471
--
6472

  
6473

  
6474

  
6475

  
6476

  
6477

  
6478

  
6479
--
6470 6480
-- Name: family_higher_plant_group; Type: ACL; Schema: public; Owner: -
6471 6481
--
6472 6482

  
......
6717 6727

  
6718 6728

  
6719 6729
--
6720
-- Name: cultivated_family_locations; Type: ACL; Schema: public; Owner: -
6721
--
6722

  
6723

  
6724

  
6725

  
6726

  
6727

  
6728

  
6729
--
6730 6730
-- Name: definedvalue; Type: ACL; Schema: public; Owner: -
6731 6731
--
6732 6732

  
schemas/vegbien.sql
1509 1509

  
1510 1510

  
1511 1511
--
1512
-- Name: cultivated_family_locations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1513
--
1514

  
1515
CREATE TABLE cultivated_family_locations (
1516
    family text NOT NULL,
1517
    country text NOT NULL
1518
);
1519

  
1520

  
1521
--
1512 1522
-- Name: family_higher_plant_group; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1513 1523
--
1514 1524

  
......
2198 2208
--
2199 2209

  
2200 2210
CREATE VIEW analytical_stem_view AS
2201
    SELECT source.shortname AS "institutionCode", 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, "newWorldCountries"."isNewWorld", _m_to_km(canon_place.distance_to_country_m) AS "distanceToCountry_km", _m_to_km(canon_place.distance_to_state_m) AS "distanceToStateProvince_km", location.sourceaccessioncode AS "plotName", location.elevation_m AS "elevationInMeters", _m2_to_ha(location.area_m2) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.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", CASE WHEN (accepted_taxonlabel.rank = 'family'::taxonrank) THEN accepted_taxonverbatim.family ELSE NULLIF(array_to_string(ARRAY[accepted_taxonverbatim.genus, COALESCE(parsed_taxonverbatim.specific_epithet, parsed_taxonverbatim.morphospecies)], ' '::text), ''::text) END AS "scientificNameWithMorphospecies", (threatened_taxonlabel.taxonlabel_id IS NOT NULL) AS threatened, NULLIF(array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text), ''::text) AS "identifiedBy", taxonoccurrence.growthform AS "growthForm", COALESCE(taxonoccurrence.iscultivated, location.iscultivated, (geoscrub_cultivated."isCultivated")::boolean) AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE (geoscrub_cultivated."isCultivatedReason" || ''::text) END AS "cultivatedBasis", _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", collector.fullname AS "recordedBy", plantobservation.collectionnumber AS "recordNumber" FROM (((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationplace USING (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 geoscrub.geoscrub_cultivated ON (((geoscrub_cultivated."latitudeDecimalVerbatim" = coordinates.latitude_deg) AND (geoscrub_cultivated."longitudeDecimalVerbatim" = coordinates.longitude_deg)))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON ((("newWorldCountries"."isoCode")::text = iso_code_gadm."2-digit iso code"))) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonverbatim datasource_taxonverbatim USING (taxonverbatim_id)) 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 plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) WHERE (taxondetermination.iscurrent AND (COALESCE(locationevent.obsstartdate, aggregateoccurrence.collectiondate) IS NOT NULL));
2211
    SELECT source.shortname AS "institutionCode", 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, "newWorldCountries"."isNewWorld", _m_to_km(canon_place.distance_to_country_m) AS "distanceToCountry_km", _m_to_km(canon_place.distance_to_state_m) AS "distanceToStateProvince_km", location.sourceaccessioncode AS "plotName", location.elevation_m AS "elevationInMeters", _m2_to_ha(location.area_m2) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.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", CASE WHEN (accepted_taxonlabel.rank = 'family'::taxonrank) THEN accepted_taxonverbatim.family ELSE NULLIF(array_to_string(ARRAY[accepted_taxonverbatim.genus, COALESCE(parsed_taxonverbatim.specific_epithet, parsed_taxonverbatim.morphospecies)], ' '::text), ''::text) END AS "scientificNameWithMorphospecies", (threatened_taxonlabel.taxonlabel_id IS NOT NULL) AS threatened, NULLIF(array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text), ''::text) AS "identifiedBy", taxonoccurrence.growthform AS "growthForm", COALESCE((taxonoccurrence.iscultivated OR (cultivated_family_locations.country IS NOT NULL)), location.iscultivated, (geoscrub_cultivated."isCultivated")::boolean) AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE (geoscrub_cultivated."isCultivatedReason" || ''::text) END AS "cultivatedBasis", _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", collector.fullname AS "recordedBy", plantobservation.collectionnumber AS "recordNumber" FROM ((((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationplace USING (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 geoscrub.geoscrub_cultivated ON (((geoscrub_cultivated."latitudeDecimalVerbatim" = coordinates.latitude_deg) AND (geoscrub_cultivated."longitudeDecimalVerbatim" = coordinates.longitude_deg)))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON ((("newWorldCountries"."isoCode")::text = iso_code_gadm."2-digit iso code"))) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonverbatim datasource_taxonverbatim USING (taxonverbatim_id)) 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)) WHERE (taxondetermination.iscurrent AND (COALESCE(locationevent.obsstartdate, aggregateoccurrence.collectiondate) IS NOT NULL));
2202 2212

  
2203 2213

  
2204 2214
--
......
2672 2682

  
2673 2683

  
2674 2684
--
2675
-- Name: cultivated_family_locations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2676
--
2677

  
2678
CREATE TABLE cultivated_family_locations (
2679
    family text NOT NULL,
2680
    country text NOT NULL
2681
);
2682

  
2683

  
2684
--
2685 2685
-- Name: dba_preassignacccode_dba_requestnumber_seq; Type: SEQUENCE; Schema: public; Owner: -
2686 2686
--
2687 2687

  
......
7551 7551

  
7552 7552

  
7553 7553
--
7554
-- Name: cultivated_family_locations; Type: ACL; Schema: public; Owner: -
7555
--
7556

  
7557
REVOKE ALL ON TABLE cultivated_family_locations FROM PUBLIC;
7558
REVOKE ALL ON TABLE cultivated_family_locations FROM bien;
7559
GRANT ALL ON TABLE cultivated_family_locations TO bien;
7560
GRANT SELECT ON TABLE cultivated_family_locations TO bien_read;
7561

  
7562

  
7563
--
7554 7564
-- Name: family_higher_plant_group; Type: ACL; Schema: public; Owner: -
7555 7565
--
7556 7566

  
......
7801 7811

  
7802 7812

  
7803 7813
--
7804
-- Name: cultivated_family_locations; Type: ACL; Schema: public; Owner: -
7805
--
7806

  
7807
REVOKE ALL ON TABLE cultivated_family_locations FROM PUBLIC;
7808
REVOKE ALL ON TABLE cultivated_family_locations FROM bien;
7809
GRANT ALL ON TABLE cultivated_family_locations TO bien;
7810
GRANT SELECT ON TABLE cultivated_family_locations TO bien_read;
7811

  
7812

  
7813
--
7814 7814
-- Name: definedvalue; Type: ACL; Schema: public; Owner: -
7815 7815
--
7816 7816

  

Also available in: Unified diff