Revision 4739
Added by Aaron Marcuse-Kubitza over 12 years ago
vegbien.my.sql | ||
---|---|---|
640 | 640 |
|
641 | 641 |
|
642 | 642 |
-- |
643 |
-- Name: place; Type: TABLE; Schema: public; Owner: -; Tablespace: |
|
643 |
-- Name: placepath; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
|
644 | 644 |
-- |
645 | 645 |
|
646 |
CREATE TABLE place ( |
|
647 |
place_id int(11) NOT NULL, |
|
648 |
parent_id int(11), |
|
649 |
rank text NOT NULL, |
|
650 |
placename text NOT NULL, |
|
646 |
CREATE TABLE placepath ( |
|
647 |
placepath_id int(11) NOT NULL, |
|
648 |
datasource_id int(11) NOT NULL, |
|
651 | 649 |
placecode text, |
652 |
placedescription text, |
|
653 |
accessioncode text |
|
650 |
place_id int(11), |
|
651 |
continent text, |
|
652 |
country text, |
|
653 |
stateprovince text, |
|
654 |
county text, |
|
655 |
municipality text, |
|
656 |
site text |
|
654 | 657 |
); |
655 | 658 |
|
656 | 659 |
|
657 | 660 |
-- |
658 |
-- Name: TABLE place; Type: COMMENT; Schema: public; Owner: - |
|
661 |
-- Name: TABLE placepath; Type: COMMENT; Schema: public; Owner: -
|
|
659 | 662 |
-- |
660 | 663 |
|
661 | 664 |
|
662 | 665 |
|
663 | 666 |
|
664 | 667 |
-- |
665 |
-- Name: place_ancestor; Type: TABLE; Schema: public; Owner: -; Tablespace: |
|
666 |
-- |
|
667 |
|
|
668 |
CREATE TABLE place_ancestor ( |
|
669 |
place_id int(11) NOT NULL, |
|
670 |
ancestor_id int(11) NOT NULL |
|
671 |
); |
|
672 |
|
|
673 |
|
|
674 |
-- |
|
675 | 668 |
-- Name: plantobservation; Type: TABLE; Schema: public; Owner: -; Tablespace: |
676 | 669 |
-- |
677 | 670 |
|
... | ... | |
869 | 862 |
-- |
870 | 863 |
|
871 | 864 |
CREATE VIEW analytical_db_view AS |
872 |
SELECT datasource.organizationname AS `dataSourceName`, taxonpath.family, taxonpath.genus, taxonpath.species, COALESCE(taxonpath.scientificnamewithauthor, taxonpath.scientificname) AS taxon, taxonpath.scientificnameauthor AS `taxonAuthor`, taxonpath.variety AS `taxonMorphospecies`, country.placename AS country, stateprovince.placename AS `stateProvince`, county.placename 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`, location.area AS `plotAreaHa`, method.name AS `plotMethod`, locationcoords.latitude, locationcoords.longitude, location.elevation AS elevation_m, taxonoccurrence.iscultivated AS `isCultivated`, taxonoccurrence.cultivatedbasis AS `isCultivatedReason`, aggregateoccurrence.cover AS `pctCover` FROM ((((((((((((((((((((location JOIN party datasource ON (((datasource.party_id = location.datasource_id) AND (datasource.organizationname IS NOT NULL)))) LEFT JOIN locationcoords USING (location_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN place_ancestor continent_ancestor ON ((continent_ancestor.place_id = locationplace.placepath_id))) LEFT JOIN place continent ON (((continent.place_id = continent_ancestor.ancestor_id) AND (continent.rank = CAST('continent' AS placerank))))) LEFT JOIN place_ancestor country_ancestor ON ((country_ancestor.place_id = locationplace.placepath_id))) LEFT JOIN place country ON (((country.place_id = country_ancestor.ancestor_id) AND (country.rank = CAST('country' AS placerank))))) LEFT JOIN place_ancestor stateprovince_ancestor ON ((stateprovince_ancestor.place_id = locationplace.placepath_id))) LEFT JOIN place stateprovince ON (((stateprovince.place_id = stateprovince_ancestor.ancestor_id) AND (stateprovince.rank = CAST('stateProvince' AS placerank))))) LEFT JOIN place_ancestor county_ancestor ON ((county_ancestor.place_id = locationplace.placepath_id))) LEFT JOIN place county ON (((county.place_id = county_ancestor.ancestor_id) AND (county.rank = CAST('county' AS placerank))))) 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 taxonpath USING (taxonpath_id)) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
|
|
865 |
SELECT datasource.organizationname AS `dataSourceName`, taxonpath.family, taxonpath.genus, taxonpath.species, COALESCE(taxonpath.scientificnamewithauthor, taxonpath.scientificname) AS taxon, taxonpath.scientificnameauthor AS `taxonAuthor`, taxonpath.variety 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`, location.area AS `plotAreaHa`, method.name AS `plotMethod`, locationcoords.latitude, locationcoords.longitude, location.elevation AS elevation_m, taxonoccurrence.iscultivated AS `isCultivated`, taxonoccurrence.cultivatedbasis AS `isCultivatedReason`, aggregateoccurrence.cover AS `pctCover` FROM (((((((((((((location JOIN party datasource ON (((datasource.party_id = location.datasource_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 taxonpath USING (taxonpath_id)) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
|
|
873 | 866 |
|
874 | 867 |
|
875 | 868 |
-- |
876 |
-- Name: VIEW analytical_db_view; Type: COMMENT; Schema: public; Owner: - |
|
877 |
-- |
|
878 |
|
|
879 |
|
|
880 |
|
|
881 |
|
|
882 |
-- |
|
883 | 869 |
-- Name: classcontributor; Type: TABLE; Schema: public; Owner: -; Tablespace: |
884 | 870 |
-- |
885 | 871 |
|
... | ... | |
1567 | 1553 |
|
1568 | 1554 |
|
1569 | 1555 |
-- |
1570 |
-- Name: place_place_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
|
1556 |
-- Name: place; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
|
1571 | 1557 |
-- |
1572 | 1558 |
|
1559 |
CREATE TABLE place ( |
|
1560 |
place_id int(11) NOT NULL, |
|
1561 |
parent_id int(11), |
|
1562 |
rank text NOT NULL, |
|
1563 |
placename text NOT NULL, |
|
1564 |
placecode text, |
|
1565 |
placedescription text, |
|
1566 |
accessioncode text |
|
1567 |
); |
|
1573 | 1568 |
|
1574 | 1569 |
|
1575 |
|
|
1576 | 1570 |
-- |
1577 |
-- Name: place_place_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
|
1571 |
-- Name: TABLE place; Type: COMMENT; Schema: public; Owner: -
|
|
1578 | 1572 |
-- |
1579 | 1573 |
|
1580 | 1574 |
|
1581 | 1575 |
|
1582 | 1576 |
|
1583 | 1577 |
-- |
1584 |
-- Name: placecorrelation; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
|
1578 |
-- Name: place_ancestor; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
|
1585 | 1579 |
-- |
1586 | 1580 |
|
1587 |
CREATE TABLE placecorrelation ( |
|
1588 |
placecorrelation_id int(11) NOT NULL, |
|
1589 |
parentplace_id int(11) NOT NULL, |
|
1590 |
childplace_id int(11) NOT NULL, |
|
1591 |
placeconvergence text NOT NULL |
|
1581 |
CREATE TABLE place_ancestor ( |
|
1582 |
place_id int(11) NOT NULL, |
|
1583 |
ancestor_id int(11) NOT NULL |
|
1592 | 1584 |
); |
1593 | 1585 |
|
1594 | 1586 |
|
1595 | 1587 |
-- |
1596 |
-- Name: placecorrelation_placecorrelation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
|
1588 |
-- Name: place_place_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
|
1597 | 1589 |
-- |
1598 | 1590 |
|
1599 | 1591 |
|
1600 | 1592 |
|
1601 | 1593 |
|
1602 | 1594 |
-- |
1603 |
-- Name: placecorrelation_placecorrelation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
|
1595 |
-- Name: place_place_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
|
1604 | 1596 |
-- |
1605 | 1597 |
|
1606 | 1598 |
|
1607 | 1599 |
|
1608 | 1600 |
|
1609 | 1601 |
-- |
1610 |
-- Name: placepath; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
|
1602 |
-- Name: placecorrelation; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
|
1611 | 1603 |
-- |
1612 | 1604 |
|
1613 |
CREATE TABLE placepath ( |
|
1614 |
placepath_id int(11) NOT NULL, |
|
1615 |
datasource_id int(11) NOT NULL, |
|
1616 |
placecode text, |
|
1617 |
place_id int(11), |
|
1618 |
continent text, |
|
1619 |
country text, |
|
1620 |
stateprovince text, |
|
1621 |
county text, |
|
1622 |
municipality text, |
|
1623 |
site text |
|
1605 |
CREATE TABLE placecorrelation ( |
|
1606 |
placecorrelation_id int(11) NOT NULL, |
|
1607 |
parentplace_id int(11) NOT NULL, |
|
1608 |
childplace_id int(11) NOT NULL, |
|
1609 |
placeconvergence text NOT NULL |
|
1624 | 1610 |
); |
1625 | 1611 |
|
1626 | 1612 |
|
1627 | 1613 |
-- |
1628 |
-- Name: TABLE placepath; Type: COMMENT; Schema: public; Owner: -
|
|
1614 |
-- Name: placecorrelation_placecorrelation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
|
1629 | 1615 |
-- |
1630 | 1616 |
|
1631 | 1617 |
|
1632 | 1618 |
|
1633 | 1619 |
|
1634 | 1620 |
-- |
1621 |
-- Name: placecorrelation_placecorrelation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - |
|
1622 |
-- |
|
1623 |
|
|
1624 |
|
|
1625 |
|
|
1626 |
|
|
1627 |
-- |
|
1635 | 1628 |
-- Name: placepath_placepath_id_seq; Type: SEQUENCE; Schema: public; Owner: - |
1636 | 1629 |
-- |
1637 | 1630 |
|
Also available in: Unified diff
schemas/vegbien.sql: analytical_db_view: Use new denormalized placepath table instead of place, which significantly reduces the number of joins