Project

General

Profile

« Previous | Next » 

Revision 6179

schemas/vegbien.sql: Renamed reference -> source to make this table more broadly applicable, and because this now stores the datasource metadata

View differences:

vegbien.sql
213 213

  
214 214

  
215 215
--
216
-- Name: referencetype; Type: TYPE; Schema: public; Owner: -
217
--
218

  
219
CREATE TYPE referencetype AS ENUM (
220
    'herbarium',
221
    'primary database',
222
    'aggregator',
223
    'book',
224
    'article',
225
    'chapter',
226
    'conference proceedings',
227
    'dissertation',
228
    'edited book',
229
    'generic',
230
    'journal',
231
    'manuscript',
232
    'personal communication',
233
    'presentation',
234
    'report',
235
    'thesis',
236
    'website'
237
);
238

  
239

  
240
--
241
-- Name: TYPE referencetype; Type: COMMENT; Schema: public; Owner: -
242
--
243

  
244
COMMENT ON TYPE referencetype IS 'From <https://projects.nceas.ucsb.edu/nceas/attachments/download/428/bien_web_datasource_schema.sql>, <http://vegbank.org/vegbank/views/dba_fielddescription_detail.jsp?view=detail&wparam=1300&entity=dba_fielddescription&params=1300>, <http://vegbiendev.nceas.ucsb.edu/phppgadmin/display.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=VegBank&table=reference&subject=table#referencetype>';
245

  
246

  
247
--
248 216
-- Name: relationship; Type: TYPE; Schema: public; Owner: -
249 217
--
250 218

  
......
278 246

  
279 247

  
280 248
--
249
-- Name: sourcetype; Type: TYPE; Schema: public; Owner: -
250
--
251

  
252
CREATE TYPE sourcetype AS ENUM (
253
    'herbarium',
254
    'primary database',
255
    'aggregator',
256
    'book',
257
    'article',
258
    'chapter',
259
    'conference proceedings',
260
    'dissertation',
261
    'edited book',
262
    'generic',
263
    'journal',
264
    'manuscript',
265
    'personal communication',
266
    'presentation',
267
    'report',
268
    'thesis',
269
    'website'
270
);
271

  
272

  
273
--
274
-- Name: TYPE sourcetype; Type: COMMENT; Schema: public; Owner: -
275
--
276

  
277
COMMENT ON TYPE sourcetype IS 'From <https://projects.nceas.ucsb.edu/nceas/attachments/download/428/bien_web_datasource_schema.sql>, <http://vegbank.org/vegbank/views/dba_fielddescription_detail.jsp?view=detail&wparam=1300&entity=dba_fielddescription&params=1300>, <http://vegbiendev.nceas.ucsb.edu/phppgadmin/display.php?server=localhost%3A5432%3Aallow&database=vegbien&schema=VegBank&table=source&subject=table#sourcetype>';
278

  
279

  
280
--
281 281
-- Name: taxonclass; Type: TYPE; Schema: public; Owner: -
282 282
--
283 283

  
......
527 527
    LANGUAGE plpgsql
528 528
    AS $$
529 529
DECLARE
530
    reference_id_ integer :=
531
        (SELECT reference_id FROM reference WHERE shortname = 'NCBI');
530
    source_id_ integer :=
531
        (SELECT source_id FROM source WHERE shortname = 'NCBI');
532 532
    row_ higher_plant_group_nodes%ROWTYPE;
533 533
BEGIN
534 534
    TRUNCATE family_higher_plant_group;
......
540 540
        DECLARE
541 541
            higher_plant_group_id integer := (
542 542
                SELECT taxonlabel_id FROM taxonlabel
543
                WHERE reference_id = reference_id_
543
                WHERE source_id = source_id_
544 544
                AND taxonomicname = row_.node_name
545 545
            );
546 546
            family text;
......
551 551
                JOIN taxonlabel ON taxonlabel_id = descendant_id
552 552
                WHERE ancestor_id = higher_plant_group_id
553 553
                AND rank = 'family'
554
                AND reference_id = reference_id_
554
                AND source_id = source_id_
555 555
            LOOP
556 556
                BEGIN
557 557
                    INSERT INTO family_higher_plant_group
......
568 568

  
569 569

  
570 570
--
571
-- Name: party_reference_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
571
-- Name: party_source_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
572 572
--
573 573

  
574
CREATE FUNCTION party_reference_id_self_ref() RETURNS trigger
574
CREATE FUNCTION party_source_id_self_ref() RETURNS trigger
575 575
    LANGUAGE plpgsql
576 576
    AS $$
577 577
BEGIN
578 578
    IF new.party_id IS NULL THEN -- prepopulate party_id
579 579
        new.party_id = nextval('party_party_id_seq'::regclass);
580 580
    END IF;
581
    IF new.reference_id = 0 THEN -- make self-reference
582
        new.reference_id = new.party_id;
581
    IF new.source_id = 0 THEN -- make self-source
582
        new.source_id = new.party_id;
583 583
    END IF;
584 584
    RETURN new;
585 585
END;
......
597 597
    IF new.place_id IS NULL THEN -- prepopulate place_id
598 598
        new.place_id = nextval('place_place_id_seq'::regclass);
599 599
    END IF;
600
    IF new.matched_place_id = 0 THEN -- make self-reference
600
    IF new.matched_place_id = 0 THEN -- make self-source
601 601
        new.matched_place_id = new.place_id;
602 602
    END IF;
603 603
    RETURN new;
......
615 615

  
616 616
CREATE TABLE place (
617 617
    place_id integer NOT NULL,
618
    reference_id integer NOT NULL,
618
    source_id integer NOT NULL,
619 619
    placecode text,
620 620
    canon_place_id integer,
621 621
    matched_place_id integer,
......
626 626
    stateprovince text,
627 627
    county text,
628 628
    description text,
629
    georeference_valid boolean,
629
    geosource_valid boolean,
630 630
    distance_to_country_m double precision,
631 631
    distance_to_state_m double precision,
632 632
    CONSTRAINT place_required_key CHECK (((((((placecode IS NOT NULL) OR (coordinates_id IS NOT NULL)) OR (continent IS NOT NULL)) OR (country IS NOT NULL)) OR (stateprovince IS NOT NULL)) OR (county IS NOT NULL)))
......
662 662
    IF NOT is_update
663 663
        OR new.matched_place_id IS DISTINCT FROM old_matched_place_id THEN
664 664
        IF new.matched_place_id IS NOT NULL THEN
665
            IF new.matched_place_id = new.place_id THEN -- self-reference
666
                new.canon_place_id := new.place_id; -- make self-reference
665
            IF new.matched_place_id = new.place_id THEN -- self-source
666
                new.canon_place_id := new.place_id; -- make self-source
667 667
            ELSE -- propagate from matched place
668 668
                new.canon_place_id := (
669 669
                    SELECT canon_place_id
......
681 681
                ;
682 682
            END IF;
683 683
        ELSE -- no matched place
684
            new.canon_place_id := new.place_id; -- make self-reference
684
            new.canon_place_id := new.place_id; -- make self-source
685 685
        END IF;
686 686
    END IF;
687 687
    
......
790 790

  
791 791

  
792 792
--
793
-- Name: reference_by_shortname(text); Type: FUNCTION; Schema: public; Owner: -
793
-- Name: source_by_shortname(text); Type: FUNCTION; Schema: public; Owner: -
794 794
--
795 795

  
796
CREATE FUNCTION reference_by_shortname(shortname text) RETURNS integer
796
CREATE FUNCTION source_by_shortname(shortname text) RETURNS integer
797 797
    LANGUAGE sql STABLE STRICT
798 798
    AS $_$
799
SELECT reference_id FROM reference WHERE shortname = $1 LIMIT 1
799
SELECT source_id FROM source WHERE shortname = $1 LIMIT 1
800 800
$_$;
801 801

  
802 802

  
......
847 847
    IF new.taxonlabel_id IS NULL THEN -- prepopulate taxonlabel_id
848 848
        new.taxonlabel_id = nextval('taxonlabel_taxonlabel_id_seq'::regclass);
849 849
    END IF;
850
    IF new.matched_label_id = 0 THEN -- make self-reference
850
    IF new.matched_label_id = 0 THEN -- make self-source
851 851
        new.matched_label_id = new.taxonlabel_id;
852 852
    END IF;
853 853
    RETURN new;
......
923 923

  
924 924
CREATE TABLE taxonlabel (
925 925
    taxonlabel_id integer NOT NULL,
926
    reference_id integer NOT NULL,
926
    source_id integer NOT NULL,
927 927
    sourceaccessioncode text,
928 928
    creationdate date,
929 929
    taxonstatus taxonomic_status,
......
954 954

  
955 955

  
956 956
--
957
-- Name: COLUMN taxonlabel.reference_id; Type: COMMENT; Schema: public; Owner: -
957
-- Name: COLUMN taxonlabel.source_id; Type: COMMENT; Schema: public; Owner: -
958 958
--
959 959

  
960
COMMENT ON COLUMN taxonlabel.reference_id IS 'The entity that created the taxon label.';
960
COMMENT ON COLUMN taxonlabel.source_id IS 'The entity that created the taxon label.';
961 961

  
962 962

  
963 963
--
......
1040 1040
    IF NOT is_update
1041 1041
        OR new.matched_label_id IS DISTINCT FROM old_matched_label_id THEN
1042 1042
        IF new.matched_label_id IS NOT NULL THEN
1043
            IF new.matched_label_id = new.taxonlabel_id THEN -- self-reference
1044
                new.canon_label_id := new.taxonlabel_id; -- make self-reference
1043
            IF new.matched_label_id = new.taxonlabel_id THEN -- self-source
1044
                new.canon_label_id := new.taxonlabel_id; -- make self-source
1045 1045
            ELSE -- propagate from matched label
1046 1046
                new.canon_label_id := (
1047 1047
                    SELECT canon_label_id
......
1059 1059
                ;
1060 1060
            END IF;
1061 1061
        ELSE -- no matched taxonlabel
1062
            new.canon_label_id := new.taxonlabel_id; -- make self-reference
1062
            new.canon_label_id := new.taxonlabel_id; -- make self-source
1063 1063
        END IF;
1064 1064
    END IF;
1065 1065
    
......
1233 1233

  
1234 1234
CREATE TABLE aggregateoccurrence (
1235 1235
    aggregateoccurrence_id integer NOT NULL,
1236
    reference_id integer NOT NULL,
1236
    source_id integer NOT NULL,
1237 1237
    sourceaccessioncode text,
1238 1238
    taxonoccurrence_id integer,
1239 1239
    collectiondate date,
......
1310 1310
    county text,
1311 1311
    "decimalLatitude" double precision,
1312 1312
    "decimalLongitude" double precision,
1313
    "georeferenceValid" boolean,
1313
    "geosourceValid" boolean,
1314 1314
    "isNewWorld" boolean,
1315 1315
    "distanceToCountry_km" double precision,
1316 1316
    "distanceToStateProvince_km" double precision,
......
1349 1349
    county text,
1350 1350
    "decimalLatitude" double precision,
1351 1351
    "decimalLongitude" double precision,
1352
    "georeferenceValid" boolean,
1352
    "geosourceValid" boolean,
1353 1353
    "isNewWorld" boolean,
1354 1354
    "distanceToCountry_km" double precision,
1355 1355
    "distanceToStateProvince_km" double precision,
......
1386 1386
--
1387 1387

  
1388 1388
CREATE VIEW analytical_aggregate_view AS
1389
    SELECT analytical_stem."institutionCode", analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."georeferenceValid", analytical_stem."isNewWorld", analytical_stem."distanceToCountry_km", analytical_stem."distanceToStateProvince_km", analytical_stem."plotName", 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."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."georeferenceValid", analytical_stem."isNewWorld", analytical_stem."distanceToCountry_km", analytical_stem."distanceToStateProvince_km", analytical_stem."plotName", 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."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis";
1389
    SELECT analytical_stem."institutionCode", analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."geosourceValid", analytical_stem."isNewWorld", analytical_stem."distanceToCountry_km", analytical_stem."distanceToStateProvince_km", analytical_stem."plotName", 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."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."geosourceValid", analytical_stem."isNewWorld", analytical_stem."distanceToCountry_km", analytical_stem."distanceToStateProvince_km", analytical_stem."plotName", 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."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis";
1390 1390

  
1391 1391

  
1392 1392
--
......
1395 1395

  
1396 1396
CREATE TABLE coordinates (
1397 1397
    coordinates_id integer NOT NULL,
1398
    reference_id integer NOT NULL,
1398
    source_id integer NOT NULL,
1399 1399
    latitude_deg double precision NOT NULL,
1400 1400
    longitude_deg double precision NOT NULL,
1401 1401
    verbatimlatitude text,
......
1436 1436

  
1437 1437
CREATE TABLE location (
1438 1438
    location_id integer NOT NULL,
1439
    reference_id integer NOT NULL,
1439
    source_id integer NOT NULL,
1440 1440
    sourceaccessioncode text,
1441 1441
    parent_id integer,
1442 1442
    authorlocationcode text,
......
1495 1495

  
1496 1496
CREATE TABLE locationevent (
1497 1497
    locationevent_id integer NOT NULL,
1498
    reference_id integer NOT NULL,
1498
    source_id integer NOT NULL,
1499 1499
    sourceaccessioncode text,
1500 1500
    parent_id integer,
1501 1501
    location_id integer,
......
1606 1606

  
1607 1607
CREATE TABLE method (
1608 1608
    method_id integer NOT NULL,
1609
    reference_id integer NOT NULL,
1609
    source_id integer NOT NULL,
1610 1610
    name text,
1611 1611
    description text,
1612 1612
    diameterheight_m double precision,
......
1644 1644

  
1645 1645

  
1646 1646
--
1647
-- Name: COLUMN method.reference_id; Type: COMMENT; Schema: public; Owner: -
1647
-- Name: COLUMN method.source_id; Type: COMMENT; Schema: public; Owner: -
1648 1648
--
1649 1649

  
1650
COMMENT ON COLUMN method.reference_id IS 'Use the reference table (e.g. reference.url) to store a link to the original plain text description.';
1650
COMMENT ON COLUMN method.source_id IS 'Use the source table (e.g. source.url) to store a link to the original plain text description.';
1651 1651

  
1652 1652

  
1653 1653
--
......
1796 1796

  
1797 1797
CREATE TABLE party (
1798 1798
    party_id integer NOT NULL,
1799
    reference_id integer NOT NULL,
1799
    source_id integer NOT NULL,
1800 1800
    fullname text,
1801 1801
    salutation text,
1802 1802
    givenname text,
......
1811 1811
    partytype text,
1812 1812
    partypublic boolean DEFAULT true,
1813 1813
    accessioncode text,
1814
    CONSTRAINT party_required_key CHECK (((organizationname IS NOT NULL) OR ((reference_id <> party_id) AND ((fullname IS NOT NULL) OR (surname IS NOT NULL)))))
1814
    CONSTRAINT party_required_key CHECK (((organizationname IS NOT NULL) OR ((source_id <> party_id) AND ((fullname IS NOT NULL) OR (surname IS NOT NULL)))))
1815 1815
);
1816 1816

  
1817 1817

  
......
1821 1821

  
1822 1822
CREATE TABLE plantobservation (
1823 1823
    plantobservation_id integer NOT NULL,
1824
    reference_id integer NOT NULL,
1824
    source_id integer NOT NULL,
1825 1825
    sourceaccessioncode text,
1826 1826
    aggregateoccurrence_id integer,
1827 1827
    overallheight_m double precision,
......
1849 1849

  
1850 1850

  
1851 1851
--
1852
-- Name: reference; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1852
-- Name: source; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1853 1853
--
1854 1854

  
1855
CREATE TABLE reference (
1856
    reference_id integer NOT NULL,
1855
CREATE TABLE source (
1856
    source_id integer NOT NULL,
1857 1857
    shortname text,
1858 1858
    fulltext text,
1859
    referencetype referencetype,
1859
    sourcetype sourcetype,
1860 1860
    accesslevel text,
1861 1861
    accessconditions text,
1862 1862
    title text,
1863 1863
    titlesuperior text,
1864
    referencejournal_id integer,
1864
    sourcejournal_id integer,
1865 1865
    volume text,
1866 1866
    issue text,
1867 1867
    pagerange text,
......
1891 1891

  
1892 1892
CREATE TABLE stemobservation (
1893 1893
    stemobservation_id integer NOT NULL,
1894
    reference_id integer NOT NULL,
1894
    source_id integer NOT NULL,
1895 1895
    sourceaccessioncode text,
1896 1896
    plantobservation_id integer NOT NULL,
1897 1897
    authorstemcode text,
......
1936 1936
    party_id integer,
1937 1937
    role role DEFAULT 'unknown'::role NOT NULL,
1938 1938
    determinationtype text,
1939
    reference_id integer,
1939
    source_id integer,
1940 1940
    isoriginal boolean DEFAULT false NOT NULL,
1941 1941
    iscurrent boolean DEFAULT false NOT NULL,
1942 1942
    taxonfit text,
......
1964 1964

  
1965 1965
CREATE TABLE taxonoccurrence (
1966 1966
    taxonoccurrence_id integer NOT NULL,
1967
    reference_id integer NOT NULL,
1967
    source_id integer NOT NULL,
1968 1968
    sourceaccessioncode text,
1969 1969
    locationevent_id integer,
1970 1970
    authortaxoncode text,
......
2107 2107
--
2108 2108

  
2109 2109
CREATE VIEW analytical_stem_view AS
2110
    SELECT reference.shortname AS "institutionCode", canon_place.country, canon_place.stateprovince AS "stateProvince", datasource_place.county, coordinates.latitude_deg AS "decimalLatitude", coordinates.longitude_deg AS "decimalLongitude", canon_place.georeference_valid AS "georeferenceValid", "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", 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[accepted_taxonlabel.taxonomicname, parsed_taxonverbatim.morphospecies], ' '::text), ''::text) 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, (geoscrub_cultivated."isCultivated")::boolean) AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis 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", taxonoccurrence.collector_id AS "recordedBy", plantobservation.collectionnumber AS "recordNumber" FROM (((((((((((((((((((((((reference JOIN location USING (reference_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"."newWorldCountries" ON (("newWorldCountries"."countryNameStd" = canon_place.country))) 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 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 (NOT taxondetermination.isoriginal);
2110
    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", canon_place.geosource_valid AS "geosourceValid", "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", 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[accepted_taxonlabel.taxonomicname, parsed_taxonverbatim.morphospecies], ' '::text), ''::text) 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, (geoscrub_cultivated."isCultivated")::boolean) AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis 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", taxonoccurrence.collector_id 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"."newWorldCountries" ON (("newWorldCountries"."countryNameStd" = canon_place.country))) 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 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 (NOT taxondetermination.isoriginal);
2111 2111

  
2112 2112

  
2113 2113
--
......
2202 2202
CREATE TABLE commconcept (
2203 2203
    commconcept_id integer NOT NULL,
2204 2204
    commname_id integer NOT NULL,
2205
    reference_id integer,
2205
    source_id integer,
2206 2206
    commdescription text,
2207 2207
    commname text,
2208 2208
    accessioncode text
......
2360 2360
CREATE TABLE commname (
2361 2361
    commname_id integer NOT NULL,
2362 2362
    commname text NOT NULL,
2363
    reference_id integer,
2363
    source_id integer,
2364 2364
    dateentered date DEFAULT now()
2365 2365
);
2366 2366

  
......
2397 2397
CREATE TABLE commstatus (
2398 2398
    commstatus_id integer NOT NULL,
2399 2399
    commconcept_id integer NOT NULL,
2400
    reference_id integer,
2400
    source_id integer,
2401 2401
    commconceptstatus text NOT NULL,
2402 2402
    commparent_id integer,
2403 2403
    commlevel text,
......
2548 2548

  
2549 2549
CREATE TABLE covermethod (
2550 2550
    covermethod_id integer NOT NULL,
2551
    reference_id integer,
2551
    source_id integer,
2552 2552
    covertype text NOT NULL,
2553 2553
    coverestimationmethod text,
2554 2554
    accessioncode text
......
3321 3321

  
3322 3322
CREATE TABLE project (
3323 3323
    project_id integer NOT NULL,
3324
    reference_id integer NOT NULL,
3324
    source_id integer NOT NULL,
3325 3325
    sourceaccessioncode text,
3326 3326
    projectname text,
3327 3327
    projectdescription text,
......
3397 3397

  
3398 3398

  
3399 3399
--
3400
-- Name: reference_reference_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3400
-- Name: revision; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3401 3401
--
3402 3402

  
3403
CREATE SEQUENCE reference_reference_id_seq
3403
CREATE TABLE revision (
3404
    revision_id integer NOT NULL,
3405
    tablename text NOT NULL,
3406
    tableattribute text NOT NULL,
3407
    tablerecord integer NOT NULL,
3408
    previousvaluetext text NOT NULL,
3409
    previousvaluetype text NOT NULL,
3410
    previousrevision_id integer,
3411
    revisiondate date NOT NULL
3412
);
3413

  
3414

  
3415
--
3416
-- Name: revision_revision_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3417
--
3418

  
3419
CREATE SEQUENCE revision_revision_id_seq
3404 3420
    START WITH 1
3405 3421
    INCREMENT BY 1
3406 3422
    NO MINVALUE
......
3409 3425

  
3410 3426

  
3411 3427
--
3412
-- Name: reference_reference_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3428
-- Name: revision_revision_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3413 3429
--
3414 3430

  
3415
ALTER SEQUENCE reference_reference_id_seq OWNED BY reference.reference_id;
3431
ALTER SEQUENCE revision_revision_id_seq OWNED BY revision.revision_id;
3416 3432

  
3417 3433

  
3418 3434
--
3419
-- Name: reference_reference_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3435
-- Name: revision_revision_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3420 3436
--
3421 3437

  
3422 3438

  
3423 3439

  
3424 3440
--
3425
-- Name: referencecontributor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3441
-- Name: soilobs; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3426 3442
--
3427 3443

  
3428
CREATE TABLE referencecontributor (
3429
    referencecontributor_id integer NOT NULL,
3430
    reference_id integer NOT NULL,
3431
    referenceparty_id integer NOT NULL,
3432
    roletype text,
3433
    "position" integer
3444
CREATE TABLE soilobs (
3445
    soilobs_id integer NOT NULL,
3446
    locationevent_id integer NOT NULL,
3447
    horizon text DEFAULT 'unknown'::text NOT NULL,
3448
    description text,
3449
    depthtop_m double precision,
3450
    depthbottom_m double precision,
3451
    color text,
3452
    texture text,
3453
    organic_fraction double precision,
3454
    sand_fraction double precision,
3455
    silt_fraction double precision,
3456
    clay_fraction double precision,
3457
    coarse_fraction double precision,
3458
    ph double precision,
3459
    acidity_fraction double precision,
3460
    basesaturation_fraction double precision,
3461
    cationexchangecapacity_cmol_kg double precision,
3462
    conductivity double precision,
3463
    carbon_fraction double precision,
3464
    phosphorus_fraction double precision,
3465
    potassium_fraction double precision,
3466
    magnesium_fraction double precision,
3467
    nitrogen_fraction double precision,
3468
    calcium_fraction double precision,
3469
    sodium_fraction double precision
3434 3470
);
3435 3471

  
3436 3472

  
3437 3473
--
3438
-- Name: referencecontributor_referencecontributor_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3474
-- Name: soilobs_soilobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3439 3475
--
3440 3476

  
3441
CREATE SEQUENCE referencecontributor_referencecontributor_id_seq
3477
CREATE SEQUENCE soilobs_soilobs_id_seq
3442 3478
    START WITH 1
3443 3479
    INCREMENT BY 1
3444 3480
    NO MINVALUE
......
3447 3483

  
3448 3484

  
3449 3485
--
3450
-- Name: referencecontributor_referencecontributor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3486
-- Name: soilobs_soilobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3451 3487
--
3452 3488

  
3453
ALTER SEQUENCE referencecontributor_referencecontributor_id_seq OWNED BY referencecontributor.referencecontributor_id;
3489
ALTER SEQUENCE soilobs_soilobs_id_seq OWNED BY soilobs.soilobs_id;
3454 3490

  
3455 3491

  
3456 3492
--
3457
-- Name: referencecontributor_referencecontributor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3493
-- Name: soilobs_soilobs_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3458 3494
--
3459 3495

  
3460 3496

  
3461 3497

  
3462 3498
--
3463
-- Name: referencejournal; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3499
-- Name: soiltaxon; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3464 3500
--
3465 3501

  
3466
CREATE TABLE referencejournal (
3467
    referencejournal_id integer NOT NULL,
3468
    journal text NOT NULL,
3469
    issn text,
3470
    abbreviation text,
3502
CREATE TABLE soiltaxon (
3503
    soiltaxon_id integer NOT NULL,
3504
    soilcode text,
3505
    soilname text,
3506
    soillevel integer,
3507
    soilparent_id integer,
3508
    soilframework text,
3471 3509
    accessioncode text
3472 3510
);
3473 3511

  
3474 3512

  
3475 3513
--
3476
-- Name: referencejournal_referencejournal_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3514
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3477 3515
--
3478 3516

  
3479
CREATE SEQUENCE referencejournal_referencejournal_id_seq
3517
CREATE SEQUENCE soiltaxon_soiltaxon_id_seq
3480 3518
    START WITH 1
3481 3519
    INCREMENT BY 1
3482 3520
    NO MINVALUE
......
3485 3523

  
3486 3524

  
3487 3525
--
3488
-- Name: referencejournal_referencejournal_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3526
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3489 3527
--
3490 3528

  
3491
ALTER SEQUENCE referencejournal_referencejournal_id_seq OWNED BY referencejournal.referencejournal_id;
3529
ALTER SEQUENCE soiltaxon_soiltaxon_id_seq OWNED BY soiltaxon.soiltaxon_id;
3492 3530

  
3493 3531

  
3494 3532
--
3495
-- Name: referencejournal_referencejournal_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3533
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3496 3534
--
3497 3535

  
3498 3536

  
3499 3537

  
3500 3538
--
3501
-- Name: referencename; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3539
-- Name: source_source_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3502 3540
--
3503 3541

  
3504
CREATE TABLE referencename (
3505
    referencename_id integer NOT NULL,
3506
    reference_id integer NOT NULL,
3507
    system text,
3508
    name text NOT NULL,
3509
    matched_reference_id integer
3510
);
3511

  
3512

  
3513
--
3514
-- Name: referencename_referencename_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3515
--
3516

  
3517
CREATE SEQUENCE referencename_referencename_id_seq
3542
CREATE SEQUENCE source_source_id_seq
3518 3543
    START WITH 1
3519 3544
    INCREMENT BY 1
3520 3545
    NO MINVALUE
......
3523 3548

  
3524 3549

  
3525 3550
--
3526
-- Name: referencename_referencename_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3551
-- Name: source_source_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3527 3552
--
3528 3553

  
3529
ALTER SEQUENCE referencename_referencename_id_seq OWNED BY referencename.referencename_id;
3554
ALTER SEQUENCE source_source_id_seq OWNED BY source.source_id;
3530 3555

  
3531 3556

  
3532 3557
--
3533
-- Name: referencename_referencename_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3558
-- Name: source_source_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3534 3559
--
3535 3560

  
3536 3561

  
3537 3562

  
3538 3563
--
3539
-- Name: revision; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3564
-- Name: sourcecontributor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3540 3565
--
3541 3566

  
3542
CREATE TABLE revision (
3543
    revision_id integer NOT NULL,
3544
    tablename text NOT NULL,
3545
    tableattribute text NOT NULL,
3546
    tablerecord integer NOT NULL,
3547
    previousvaluetext text NOT NULL,
3548
    previousvaluetype text NOT NULL,
3549
    previousrevision_id integer,
3550
    revisiondate date NOT NULL
3567
CREATE TABLE sourcecontributor (
3568
    sourcecontributor_id integer NOT NULL,
3569
    source_id integer NOT NULL,
3570
    sourceparty_id integer NOT NULL,
3571
    roletype text,
3572
    "position" integer
3551 3573
);
3552 3574

  
3553 3575

  
3554 3576
--
3555
-- Name: revision_revision_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3577
-- Name: sourcecontributor_sourcecontributor_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3556 3578
--
3557 3579

  
3558
CREATE SEQUENCE revision_revision_id_seq
3580
CREATE SEQUENCE sourcecontributor_sourcecontributor_id_seq
3559 3581
    START WITH 1
3560 3582
    INCREMENT BY 1
3561 3583
    NO MINVALUE
......
3564 3586

  
3565 3587

  
3566 3588
--
3567
-- Name: revision_revision_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3589
-- Name: sourcecontributor_sourcecontributor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3568 3590
--
3569 3591

  
3570
ALTER SEQUENCE revision_revision_id_seq OWNED BY revision.revision_id;
3592
ALTER SEQUENCE sourcecontributor_sourcecontributor_id_seq OWNED BY sourcecontributor.sourcecontributor_id;
3571 3593

  
3572 3594

  
3573 3595
--
3574
-- Name: revision_revision_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3596
-- Name: sourcecontributor_sourcecontributor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3575 3597
--
3576 3598

  
3577 3599

  
3578 3600

  
3579 3601
--
3580
-- Name: soilobs; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3602
-- Name: sourcejournal; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3581 3603
--
3582 3604

  
3583
CREATE TABLE soilobs (
3584
    soilobs_id integer NOT NULL,
3585
    locationevent_id integer NOT NULL,
3586
    horizon text DEFAULT 'unknown'::text NOT NULL,
3587
    description text,
3588
    depthtop_m double precision,
3589
    depthbottom_m double precision,
3590
    color text,
3591
    texture text,
3592
    organic_fraction double precision,
3593
    sand_fraction double precision,
3594
    silt_fraction double precision,
3595
    clay_fraction double precision,
3596
    coarse_fraction double precision,
3597
    ph double precision,
3598
    acidity_fraction double precision,
3599
    basesaturation_fraction double precision,
3600
    cationexchangecapacity_cmol_kg double precision,
3601
    conductivity double precision,
3602
    carbon_fraction double precision,
3603
    phosphorus_fraction double precision,
3604
    potassium_fraction double precision,
3605
    magnesium_fraction double precision,
3606
    nitrogen_fraction double precision,
3607
    calcium_fraction double precision,
3608
    sodium_fraction double precision
3605
CREATE TABLE sourcejournal (
3606
    sourcejournal_id integer NOT NULL,
3607
    journal text NOT NULL,
3608
    issn text,
3609
    abbreviation text,
3610
    accessioncode text
3609 3611
);
3610 3612

  
3611 3613

  
3612 3614
--
3613
-- Name: soilobs_soilobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3615
-- Name: sourcejournal_sourcejournal_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3614 3616
--
3615 3617

  
3616
CREATE SEQUENCE soilobs_soilobs_id_seq
3618
CREATE SEQUENCE sourcejournal_sourcejournal_id_seq
3617 3619
    START WITH 1
3618 3620
    INCREMENT BY 1
3619 3621
    NO MINVALUE
......
3622 3624

  
3623 3625

  
3624 3626
--
3625
-- Name: soilobs_soilobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3627
-- Name: sourcejournal_sourcejournal_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3626 3628
--
3627 3629

  
3628
ALTER SEQUENCE soilobs_soilobs_id_seq OWNED BY soilobs.soilobs_id;
3630
ALTER SEQUENCE sourcejournal_sourcejournal_id_seq OWNED BY sourcejournal.sourcejournal_id;
3629 3631

  
3630 3632

  
3631 3633
--
3632
-- Name: soilobs_soilobs_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3634
-- Name: sourcejournal_sourcejournal_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3633 3635
--
3634 3636

  
3635 3637

  
3636 3638

  
3637 3639
--
3638
-- Name: soiltaxon; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3640
-- Name: sourcename; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3639 3641
--
3640 3642

  
3641
CREATE TABLE soiltaxon (
3642
    soiltaxon_id integer NOT NULL,
3643
    soilcode text,
3644
    soilname text,
3645
    soillevel integer,
3646
    soilparent_id integer,
3647
    soilframework text,
3648
    accessioncode text
3643
CREATE TABLE sourcename (
3644
    sourcename_id integer NOT NULL,
3645
    source_id integer NOT NULL,
3646
    system text,
3647
    name text NOT NULL,
3648
    matched_source_id integer
3649 3649
);
3650 3650

  
3651 3651

  
3652 3652
--
3653
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3653
-- Name: sourcename_sourcename_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3654 3654
--
3655 3655

  
3656
CREATE SEQUENCE soiltaxon_soiltaxon_id_seq
3656
CREATE SEQUENCE sourcename_sourcename_id_seq
3657 3657
    START WITH 1
3658 3658
    INCREMENT BY 1
3659 3659
    NO MINVALUE
......
3662 3662

  
3663 3663

  
3664 3664
--
3665
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3665
-- Name: sourcename_sourcename_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3666 3666
--
3667 3667

  
3668
ALTER SEQUENCE soiltaxon_soiltaxon_id_seq OWNED BY soiltaxon.soiltaxon_id;
3668
ALTER SEQUENCE sourcename_sourcename_id_seq OWNED BY sourcename.sourcename_id;
3669 3669

  
3670 3670

  
3671 3671
--
3672
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3672
-- Name: sourcename_sourcename_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
3673 3673
--
3674 3674

  
3675 3675

  
......
3721 3721

  
3722 3722
CREATE TABLE specimenreplicate (
3723 3723
    specimenreplicate_id integer NOT NULL,
3724
    reference_id integer NOT NULL,
3724
    source_id integer NOT NULL,
3725 3725
    sourceaccessioncode text,
3726 3726
    plantobservation_id integer,
3727 3727
    institution_id integer,
......
3890 3890

  
3891 3891
CREATE TABLE taxonconcept (
3892 3892
    taxonlabel_id integer NOT NULL,
3893
    concept_reference_id integer
3893
    concept_source_id integer
3894 3894
);
3895 3895

  
3896 3896

  
......
3902 3902

  
3903 3903

  
3904 3904
--
3905
-- Name: COLUMN taxonconcept.concept_reference_id; Type: COMMENT; Schema: public; Owner: -
3905
-- Name: COLUMN taxonconcept.concept_source_id; Type: COMMENT; Schema: public; Owner: -
3906 3906
--
3907 3907

  
3908
COMMENT ON COLUMN taxonconcept.concept_reference_id IS 'The entity that defined the taxon concept. This is who the taxon concept is according to.
3908
COMMENT ON COLUMN taxonconcept.concept_source_id IS 'The entity that defined the taxon concept. This is who the taxon concept is according to.
3909 3909

  
3910 3910
Equivalent to "Name sec. x".';
3911 3911

  
......
4119 4119
    taxonlabel_id integer NOT NULL,
4120 4120
    party_id integer,
4121 4121
    taxonlabelstatus text DEFAULT 'undetermined'::text NOT NULL,
4122
    reference_id integer,
4122
    source_id integer,
4123 4123
    plantpartycomments text,
4124 4124
    startdate date,
4125 4125
    stopdate date,
......
4219 4219
--
4220 4220

  
4221 4221
CREATE VIEW threatened_taxonlabel_view AS
4222
    SELECT DISTINCT accepted_taxonlabel_descendant.descendant_id AS taxonlabel_id FROM ((taxonlabel datasource_taxonlabel JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.canon_label_id))) JOIN taxonlabel_relationship accepted_taxonlabel_descendant ON ((accepted_taxonlabel_descendant.ancestor_id = accepted_taxonlabel.taxonlabel_id))) WHERE (((datasource_taxonlabel.reference_id = reference_by_shortname('IUCN'::text)) AND (datasource_taxonlabel.taxonomicname IS NOT NULL)) AND (accepted_taxonlabel.rank >= 'species'::taxonrank));
4222
    SELECT DISTINCT accepted_taxonlabel_descendant.descendant_id AS taxonlabel_id FROM ((taxonlabel datasource_taxonlabel JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.canon_label_id))) JOIN taxonlabel_relationship accepted_taxonlabel_descendant ON ((accepted_taxonlabel_descendant.ancestor_id = accepted_taxonlabel.taxonlabel_id))) WHERE (((datasource_taxonlabel.source_id = source_by_shortname('IUCN'::text)) AND (datasource_taxonlabel.taxonomicname IS NOT NULL)) AND (accepted_taxonlabel.rank >= 'species'::taxonrank));
4223 4223

  
4224 4224

  
4225 4225
--
......
4589 4589

  
4590 4590

  
4591 4591
--
4592
-- Name: reference_id; Type: DEFAULT; Schema: public; Owner: -
4592
-- Name: revision_id; Type: DEFAULT; Schema: public; Owner: -
4593 4593
--
4594 4594

  
4595
ALTER TABLE reference ALTER COLUMN reference_id SET DEFAULT nextval('reference_reference_id_seq'::regclass);
4595
ALTER TABLE revision ALTER COLUMN revision_id SET DEFAULT nextval('revision_revision_id_seq'::regclass);
4596 4596

  
4597 4597

  
4598 4598
--
4599
-- Name: referencecontributor_id; Type: DEFAULT; Schema: public; Owner: -
4599
-- Name: soilobs_id; Type: DEFAULT; Schema: public; Owner: -
4600 4600
--
4601 4601

  
4602
ALTER TABLE referencecontributor ALTER COLUMN referencecontributor_id SET DEFAULT nextval('referencecontributor_referencecontributor_id_seq'::regclass);
4602
ALTER TABLE soilobs ALTER COLUMN soilobs_id SET DEFAULT nextval('soilobs_soilobs_id_seq'::regclass);
4603 4603

  
4604 4604

  
4605 4605
--
4606
-- Name: referencejournal_id; Type: DEFAULT; Schema: public; Owner: -
4606
-- Name: soiltaxon_id; Type: DEFAULT; Schema: public; Owner: -
4607 4607
--
4608 4608

  
4609
ALTER TABLE referencejournal ALTER COLUMN referencejournal_id SET DEFAULT nextval('referencejournal_referencejournal_id_seq'::regclass);
4609
ALTER TABLE soiltaxon ALTER COLUMN soiltaxon_id SET DEFAULT nextval('soiltaxon_soiltaxon_id_seq'::regclass);
4610 4610

  
4611 4611

  
4612 4612
--
4613
-- Name: referencename_id; Type: DEFAULT; Schema: public; Owner: -
4613
-- Name: source_id; Type: DEFAULT; Schema: public; Owner: -
4614 4614
--
4615 4615

  
4616
ALTER TABLE referencename ALTER COLUMN referencename_id SET DEFAULT nextval('referencename_referencename_id_seq'::regclass);
4616
ALTER TABLE source ALTER COLUMN source_id SET DEFAULT nextval('source_source_id_seq'::regclass);
4617 4617

  
4618 4618

  
4619 4619
--
4620
-- Name: revision_id; Type: DEFAULT; Schema: public; Owner: -
4620
-- Name: sourcecontributor_id; Type: DEFAULT; Schema: public; Owner: -
4621 4621
--
4622 4622

  
4623
ALTER TABLE revision ALTER COLUMN revision_id SET DEFAULT nextval('revision_revision_id_seq'::regclass);
4623
ALTER TABLE sourcecontributor ALTER COLUMN sourcecontributor_id SET DEFAULT nextval('sourcecontributor_sourcecontributor_id_seq'::regclass);
4624 4624

  
4625 4625

  
4626 4626
--
4627
-- Name: soilobs_id; Type: DEFAULT; Schema: public; Owner: -
4627
-- Name: sourcejournal_id; Type: DEFAULT; Schema: public; Owner: -
4628 4628
--
4629 4629

  
4630
ALTER TABLE soilobs ALTER COLUMN soilobs_id SET DEFAULT nextval('soilobs_soilobs_id_seq'::regclass);
4630
ALTER TABLE sourcejournal ALTER COLUMN sourcejournal_id SET DEFAULT nextval('sourcejournal_sourcejournal_id_seq'::regclass);
4631 4631

  
4632 4632

  
4633 4633
--
4634
-- Name: soiltaxon_id; Type: DEFAULT; Schema: public; Owner: -
4634
-- Name: sourcename_id; Type: DEFAULT; Schema: public; Owner: -
4635 4635
--
4636 4636

  
4637
ALTER TABLE soiltaxon ALTER COLUMN soiltaxon_id SET DEFAULT nextval('soiltaxon_soiltaxon_id_seq'::regclass);
4637
ALTER TABLE sourcename ALTER COLUMN sourcename_id SET DEFAULT nextval('sourcename_sourcename_id_seq'::regclass);
4638 4638

  
4639 4639

  
4640 4640
--
......
5008 5008

  
5009 5009

  
5010 5010
--
5011
-- Data for Name: reference; Type: TABLE DATA; Schema: public; Owner: -
5011
-- Data for Name: revision; Type: TABLE DATA; Schema: public; Owner: -
5012 5012
--
5013 5013

  
5014 5014

  
5015 5015

  
5016 5016
--
5017
-- Data for Name: referencecontributor; Type: TABLE DATA; Schema: public; Owner: -
5017
-- Data for Name: soilobs; Type: TABLE DATA; Schema: public; Owner: -
5018 5018
--
5019 5019

  
5020 5020

  
5021 5021

  
5022 5022
--
5023
-- Data for Name: referencejournal; Type: TABLE DATA; Schema: public; Owner: -
5023
-- Data for Name: soiltaxon; Type: TABLE DATA; Schema: public; Owner: -
5024 5024
--
5025 5025

  
5026 5026

  
5027 5027

  
5028 5028
--
5029
-- Data for Name: referencename; Type: TABLE DATA; Schema: public; Owner: -
5029
-- Data for Name: source; Type: TABLE DATA; Schema: public; Owner: -
5030 5030
--
5031 5031

  
5032 5032

  
5033 5033

  
5034 5034
--
5035
-- Data for Name: revision; Type: TABLE DATA; Schema: public; Owner: -
5035
-- Data for Name: sourcecontributor; Type: TABLE DATA; Schema: public; Owner: -
5036 5036
--
5037 5037

  
5038 5038

  
5039 5039

  
5040 5040
--
5041
-- Data for Name: soilobs; Type: TABLE DATA; Schema: public; Owner: -
5041
-- Data for Name: sourcejournal; Type: TABLE DATA; Schema: public; Owner: -
5042 5042
--
5043 5043

  
5044 5044

  
5045 5045

  
5046 5046
--
5047
-- Data for Name: soiltaxon; Type: TABLE DATA; Schema: public; Owner: -
5047
-- Data for Name: sourcename; Type: TABLE DATA; Schema: public; Owner: -
5048 5048
--
5049 5049

  
5050 5050

  
......
5512 5512
--
5513 5513

  
5514 5514
ALTER TABLE ONLY project
5515
    ADD CONSTRAINT project_unique UNIQUE (reference_id, projectname);
5515
    ADD CONSTRAINT project_unique UNIQUE (source_id, projectname);
5516 5516

  
5517 5517

  
5518 5518
--
......
5524 5524

  
5525 5525

  
5526 5526
--
5527
-- Name: reference_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5527
-- Name: revision_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5528 5528
--
5529 5529

  
5530
ALTER TABLE ONLY reference
5531
    ADD CONSTRAINT reference_pkey PRIMARY KEY (reference_id);
5530
ALTER TABLE ONLY revision
5531
    ADD CONSTRAINT revision_pkey PRIMARY KEY (revision_id);
5532 5532

  
5533 5533

  
5534 5534
--
5535
-- Name: referencecontributor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5535
-- Name: soilobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5536 5536
--
5537 5537

  
5538
ALTER TABLE ONLY referencecontributor
5539
    ADD CONSTRAINT referencecontributor_pkey PRIMARY KEY (referencecontributor_id);
5538
ALTER TABLE ONLY soilobs
5539
    ADD CONSTRAINT soilobs_pkey PRIMARY KEY (soilobs_id);
5540 5540

  
5541 5541

  
5542 5542
--
5543
-- Name: referencejournal_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5543
-- Name: soilobs_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5544 5544
--
5545 5545

  
5546
ALTER TABLE ONLY referencejournal
5547
    ADD CONSTRAINT referencejournal_pkey PRIMARY KEY (referencejournal_id);
5546
ALTER TABLE ONLY soilobs
5547
    ADD CONSTRAINT soilobs_unique UNIQUE (locationevent_id);
5548 5548

  
5549 5549

  
5550 5550
--
5551
-- Name: referencename_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5551
-- Name: soiltaxon_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5552 5552
--
5553 5553

  
5554
ALTER TABLE ONLY referencename
5555
    ADD CONSTRAINT referencename_pkey PRIMARY KEY (referencename_id);
5554
ALTER TABLE ONLY soiltaxon
5555
    ADD CONSTRAINT soiltaxon_pkey PRIMARY KEY (soiltaxon_id);
5556 5556

  
5557 5557

  
5558 5558
--
5559
-- Name: revision_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5559
-- Name: source_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5560 5560
--
5561 5561

  
5562
ALTER TABLE ONLY revision
5563
    ADD CONSTRAINT revision_pkey PRIMARY KEY (revision_id);
5562
ALTER TABLE ONLY source
5563
    ADD CONSTRAINT source_pkey PRIMARY KEY (source_id);
5564 5564

  
5565 5565

  
5566 5566
--
5567
-- Name: soilobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5567
-- Name: sourcecontributor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5568 5568
--
5569 5569

  
5570
ALTER TABLE ONLY soilobs
5571
    ADD CONSTRAINT soilobs_pkey PRIMARY KEY (soilobs_id);
5570
ALTER TABLE ONLY sourcecontributor
5571
    ADD CONSTRAINT sourcecontributor_pkey PRIMARY KEY (sourcecontributor_id);
5572 5572

  
5573 5573

  
5574 5574
--
5575
-- Name: soilobs_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5575
-- Name: sourcejournal_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5576 5576
--
5577 5577

  
5578
ALTER TABLE ONLY soilobs
5579
    ADD CONSTRAINT soilobs_unique UNIQUE (locationevent_id);
5578
ALTER TABLE ONLY sourcejournal
5579
    ADD CONSTRAINT sourcejournal_pkey PRIMARY KEY (sourcejournal_id);
5580 5580

  
5581 5581

  
5582 5582
--
5583
-- Name: soiltaxon_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5583
-- Name: sourcename_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
5584 5584
--
5585 5585

  
5586
ALTER TABLE ONLY soiltaxon
5587
    ADD CONSTRAINT soiltaxon_pkey PRIMARY KEY (soiltaxon_id);
5586
ALTER TABLE ONLY sourcename
5587
    ADD CONSTRAINT sourcename_pkey PRIMARY KEY (sourcename_id);
5588 5588

  
5589 5589

  
5590 5590
--
......
5789 5789
-- Name: aggregateoccurrence_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5790 5790
--
5791 5791

  
5792
CREATE UNIQUE INDEX aggregateoccurrence_unique_within_creator ON aggregateoccurrence USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
5792
CREATE UNIQUE INDEX aggregateoccurrence_unique_within_creator ON aggregateoccurrence USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
5793 5793

  
5794 5794

  
5795 5795
--
......
5824 5824
-- Name: coordinates_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5825 5825
--
5826 5826

  
5827
CREATE UNIQUE INDEX coordinates_unique ON coordinates USING btree (reference_id, latitude_deg, longitude_deg, (COALESCE(verbatimlatitude, '\\N'::text)), (COALESCE(verbatimlongitude, '\\N'::text)), (COALESCE(verbatimcoordinates, '\\N'::text)), (COALESCE(footprintgeometry_dwc, '\\N'::text)));
5827
CREATE UNIQUE INDEX coordinates_unique ON coordinates USING btree (source_id, latitude_deg, longitude_deg, (COALESCE(verbatimlatitude, '\\N'::text)), (COALESCE(verbatimlongitude, '\\N'::text)), (COALESCE(verbatimcoordinates, '\\N'::text)), (COALESCE(footprintgeometry_dwc, '\\N'::text)));
5828 5828

  
5829 5829

  
5830 5830
--
......
5852 5852
-- Name: location_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5853 5853
--
5854 5854

  
5855
CREATE INDEX location_creator ON location USING btree (reference_id);
5855
CREATE INDEX location_creator ON location USING btree (source_id);
5856 5856

  
5857 5857

  
5858 5858
--
......
5866 5866
-- Name: location_unique_within_creator_by_authorlocationcode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5867 5867
--
5868 5868

  
5869
CREATE UNIQUE INDEX location_unique_within_creator_by_authorlocationcode ON location USING btree (reference_id, (COALESCE(authorlocationcode, '\\N'::text))) WHERE (((authorlocationcode IS NOT NULL) AND (parent_id IS NULL)) AND (sourceaccessioncode IS NULL));
5869
CREATE UNIQUE INDEX location_unique_within_creator_by_authorlocationcode ON location USING btree (source_id, (COALESCE(authorlocationcode, '\\N'::text))) WHERE (((authorlocationcode IS NOT NULL) AND (parent_id IS NULL)) AND (sourceaccessioncode IS NULL));
5870 5870

  
5871 5871

  
5872 5872
--
5873 5873
-- Name: location_unique_within_creator_by_sourceaccessioncode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5874 5874
--
5875 5875

  
5876
CREATE UNIQUE INDEX location_unique_within_creator_by_sourceaccessioncode ON location USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
5876
CREATE UNIQUE INDEX location_unique_within_creator_by_sourceaccessioncode ON location USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
5877 5877

  
5878 5878

  
5879 5879
--
......
5901 5901
-- Name: locationevent_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5902 5902
--
5903 5903

  
5904
CREATE UNIQUE INDEX locationevent_unique_within_creator ON locationevent USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
5904
CREATE UNIQUE INDEX locationevent_unique_within_creator ON locationevent USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
5905 5905

  
5906 5906

  
5907 5907
--
......
5957 5957
-- Name: method_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5958 5958
--
5959 5959

  
5960
CREATE UNIQUE INDEX method_unique ON method USING btree (reference_id, (COALESCE(name, '\\N'::text)), (COALESCE(description, '\\N'::text)), (COALESCE(observationmeasure, '\\N'::text)));
5960
CREATE UNIQUE INDEX method_unique ON method USING btree (source_id, (COALESCE(name, '\\N'::text)), (COALESCE(description, '\\N'::text)), (COALESCE(observationmeasure, '\\N'::text)));
5961 5961

  
5962 5962

  
5963 5963
--
......
5978 5978
-- Name: party_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5979 5979
--
5980 5980

  
5981
CREATE UNIQUE INDEX party_unique ON party USING btree (reference_id, (COALESCE(organizationname, '\\N'::text)), (COALESCE(fullname, '\\N'::text)), (COALESCE(surname, '\\N'::text)), (COALESCE(givenname, '\\N'::text)), (COALESCE(middlename, '\\N'::text)), (COALESCE(suffix, '\\N'::text)));
5981
CREATE UNIQUE INDEX party_unique ON party USING btree (source_id, (COALESCE(organizationname, '\\N'::text)), (COALESCE(fullname, '\\N'::text)), (COALESCE(surname, '\\N'::text)), (COALESCE(givenname, '\\N'::text)), (COALESCE(middlename, '\\N'::text)), (COALESCE(suffix, '\\N'::text)));
5982 5982

  
5983 5983

  
5984 5984
--
......
5992 5992
-- Name: place_unique_within_creator_by_code; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5993 5993
--
5994 5994

  
5995
CREATE UNIQUE INDEX place_unique_within_creator_by_code ON place USING btree (reference_id, (COALESCE(placecode, '\\N'::text))) WHERE (placecode IS NOT NULL);
5995
CREATE UNIQUE INDEX place_unique_within_creator_by_code ON place USING btree (source_id, (COALESCE(placecode, '\\N'::text))) WHERE (placecode IS NOT NULL);
5996 5996

  
5997 5997

  
5998 5998
--
5999 5999
-- Name: place_unique_within_creator_by_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6000 6000
--
6001 6001

  
6002
CREATE UNIQUE INDEX place_unique_within_creator_by_name ON place USING btree (reference_id, (COALESCE(continent, '\\N'::text)), (COALESCE(country, '\\N'::text)), (COALESCE(stateprovince, '\\N'::text)), (COALESCE(county, '\\N'::text)), (COALESCE(coordinates_id, 2147483647))) WHERE (placecode IS NULL);
6002
CREATE UNIQUE INDEX place_unique_within_creator_by_name ON place USING btree (source_id, (COALESCE(continent, '\\N'::text)), (COALESCE(country, '\\N'::text)), (COALESCE(stateprovince, '\\N'::text)), (COALESCE(county, '\\N'::text)), (COALESCE(coordinates_id, 2147483647))) WHERE (placecode IS NULL);
6003 6003

  
6004 6004

  
6005 6005
--
......
6020 6020
-- Name: plantobservation_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6021 6021
--
6022 6022

  
6023
CREATE UNIQUE INDEX plantobservation_unique_within_creator ON plantobservation USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6023
CREATE UNIQUE INDEX plantobservation_unique_within_creator ON plantobservation USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6024 6024

  
6025 6025

  
6026 6026
--
......
6034 6034
-- Name: project_unique_name_date; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6035 6035
--
6036 6036

  
6037
CREATE UNIQUE INDEX project_unique_name_date ON project USING btree (reference_id, (COALESCE(projectname, '\\N'::text)), (COALESCE(startdate, 'infinity'::date))) WHERE (sourceaccessioncode IS NULL);
6037
CREATE UNIQUE INDEX project_unique_name_date ON project USING btree (source_id, (COALESCE(projectname, '\\N'::text)), (COALESCE(startdate, 'infinity'::date))) WHERE (sourceaccessioncode IS NULL);
6038 6038

  
6039 6039

  
6040 6040
--
6041 6041
-- Name: project_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6042 6042
--
6043 6043

  
6044
CREATE UNIQUE INDEX project_unique_within_creator ON project USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6044
CREATE UNIQUE INDEX project_unique_within_creator ON project USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6045 6045

  
6046 6046

  
6047 6047
--
6048
-- Name: reference_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6048
-- Name: soiltaxon_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6049 6049
--
6050 6050

  
6051
CREATE UNIQUE INDEX reference_accessioncode_index ON reference USING btree (accessioncode);
6051
CREATE UNIQUE INDEX soiltaxon_accessioncode_index ON soiltaxon USING btree (accessioncode);
6052 6052

  
6053 6053

  
6054 6054
--
6055
-- Name: reference_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6055
-- Name: source_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6056 6056
--
6057 6057

  
6058
CREATE UNIQUE INDEX reference_unique ON reference USING btree ((COALESCE(shortname, '\\N'::text)));
6058
CREATE UNIQUE INDEX source_accessioncode_index ON source USING btree (accessioncode);
6059 6059

  
6060 6060

  
6061 6061
--
6062
-- Name: referencejournal_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6062
-- Name: source_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6063 6063
--
6064 6064

  
6065
CREATE UNIQUE INDEX referencejournal_accessioncode_index ON referencejournal USING btree (accessioncode);
6065
CREATE UNIQUE INDEX source_unique ON source USING btree ((COALESCE(shortname, '\\N'::text)));
6066 6066

  
6067 6067

  
6068 6068
--
6069
-- Name: referencename_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6069
-- Name: sourcejournal_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6070 6070
--
6071 6071

  
6072
CREATE UNIQUE INDEX referencename_unique ON referencename USING btree (reference_id, (COALESCE(name, '\\N'::text)));
6072
CREATE UNIQUE INDEX sourcejournal_accessioncode_index ON sourcejournal USING btree (accessioncode);
6073 6073

  
6074 6074

  
6075 6075
--
6076
-- Name: soiltaxon_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6076
-- Name: sourcename_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6077 6077
--
6078 6078

  
6079
CREATE UNIQUE INDEX soiltaxon_accessioncode_index ON soiltaxon USING btree (accessioncode);
6079
CREATE UNIQUE INDEX sourcename_unique ON sourcename USING btree (source_id, (COALESCE(name, '\\N'::text)));
6080 6080

  
6081 6081

  
6082 6082
--
......
6097 6097
-- Name: specimenreplicate_unique_catalognumber; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6098 6098
--
6099 6099

  
6100
CREATE UNIQUE INDEX specimenreplicate_unique_catalognumber ON specimenreplicate USING btree (reference_id, (COALESCE(institution_id, 2147483647)), (COALESCE(collectioncode_dwc, '\\N'::text)), (COALESCE(catalognumber_dwc, '\\N'::text)), (COALESCE(plantobservation_id, 2147483647))) WHERE ((catalognumber_dwc IS NOT NULL) AND (sourceaccessioncode IS NULL));
6100
CREATE UNIQUE INDEX specimenreplicate_unique_catalognumber ON specimenreplicate USING btree (source_id, (COALESCE(institution_id, 2147483647)), (COALESCE(collectioncode_dwc, '\\N'::text)), (COALESCE(catalognumber_dwc, '\\N'::text)), (COALESCE(plantobservation_id, 2147483647))) WHERE ((catalognumber_dwc IS NOT NULL) AND (sourceaccessioncode IS NULL));
6101 6101

  
6102 6102

  
6103 6103
--
6104 6104
-- Name: specimenreplicate_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6105 6105
--
6106 6106

  
6107
CREATE UNIQUE INDEX specimenreplicate_unique_within_creator ON specimenreplicate USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6107
CREATE UNIQUE INDEX specimenreplicate_unique_within_creator ON specimenreplicate USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6108 6108

  
6109 6109

  
6110 6110
--
......
6125 6125
-- Name: stemobservation_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6126 6126
--
6127 6127

  
6128
CREATE UNIQUE INDEX stemobservation_unique_within_creator ON stemobservation USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6128
CREATE UNIQUE INDEX stemobservation_unique_within_creator ON stemobservation USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6129 6129

  
6130 6130

  
6131 6131
--
......
6153 6153
-- Name: taxonlabel_0_unique_identifying_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6154 6154
--
6155 6155

  
6156
CREATE UNIQUE INDEX taxonlabel_0_unique_identifying_name ON taxonlabel USING btree (reference_id, (COALESCE(taxonomicname, '\\N'::text))) WHERE (taxonomicname IS NOT NULL);
6156
CREATE UNIQUE INDEX taxonlabel_0_unique_identifying_name ON taxonlabel USING btree (source_id, (COALESCE(taxonomicname, '\\N'::text))) WHERE (taxonomicname IS NOT NULL);
6157 6157

  
6158 6158

  
6159 6159
--
6160 6160
-- Name: taxonlabel_1_unique_sourceaccessioncode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6161 6161
--
6162 6162

  
6163
CREATE UNIQUE INDEX taxonlabel_1_unique_sourceaccessioncode ON taxonlabel USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6163
CREATE UNIQUE INDEX taxonlabel_1_unique_sourceaccessioncode ON taxonlabel USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6164 6164

  
6165 6165

  
6166 6166
--
......
6188 6188
-- Name: taxonlabel_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6189 6189
--
6190 6190

  
6191
CREATE UNIQUE INDEX taxonlabel_unique ON taxonlabel USING btree ((COALESCE(parent_id, 2147483647)), (COALESCE(taxonepithet, '\\N'::text)), (COALESCE(rank, 'unknown'::taxonrank)), reference_id, (COALESCE(sourceaccessioncode, '\\N'::text)), (COALESCE(taxonomicname, '\\N'::text)));
6191
CREATE UNIQUE INDEX taxonlabel_unique ON taxonlabel USING btree ((COALESCE(parent_id, 2147483647)), (COALESCE(taxonepithet, '\\N'::text)), (COALESCE(rank, 'unknown'::taxonrank)), source_id, (COALESCE(sourceaccessioncode, '\\N'::text)), (COALESCE(taxonomicname, '\\N'::text)));
6192 6192

  
6193 6193

  
6194 6194
--
......
6209 6209
-- Name: taxonoccurrence_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6210 6210
--
6211 6211

  
6212
CREATE UNIQUE INDEX taxonoccurrence_unique_within_creator ON taxonoccurrence USING btree (reference_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6212
CREATE UNIQUE INDEX taxonoccurrence_unique_within_creator ON taxonoccurrence USING btree (source_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
6213 6213

  
6214 6214

  
6215 6215
--
......
6234 6234

  
6235 6235

  
6236 6236
--
6237
-- Name: party_reference_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
6237
-- Name: party_source_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
6238 6238
--
6239 6239

  
6240
CREATE TRIGGER party_reference_id_self_ref BEFORE INSERT OR UPDATE ON party FOR EACH ROW EXECUTE PROCEDURE party_reference_id_self_ref();
6240
CREATE TRIGGER party_source_id_self_ref BEFORE INSERT OR UPDATE ON party FOR EACH ROW EXECUTE PROCEDURE party_source_id_self_ref();
6241 6241

  
6242 6242

  
6243 6243
--
......
6357 6357

  
6358 6358

  
6359 6359
--
6360
-- Name: aggregateoccurrence_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6360
-- Name: aggregateoccurrence_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6361 6361
--
6362 6362

  
6363 6363
ALTER TABLE ONLY aggregateoccurrence
6364
    ADD CONSTRAINT aggregateoccurrence_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6364
    ADD CONSTRAINT aggregateoccurrence_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6365 6365

  
6366 6366

  
6367 6367
--
......
6401 6401
--
6402 6402

  
6403 6403
ALTER TABLE ONLY commclass
6404
    ADD CONSTRAINT commclass_classpublication_id_fkey FOREIGN KEY (classpublication_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6404
    ADD CONSTRAINT commclass_classpublication_id_fkey FOREIGN KEY (classpublication_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6405 6405

  
6406 6406

  
6407 6407
--
......
6421 6421

  
6422 6422

  
6423 6423
--
6424
-- Name: commconcept_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6424
-- Name: commconcept_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6425 6425
--
6426 6426

  
6427 6427
ALTER TABLE ONLY commconcept
6428
    ADD CONSTRAINT commconcept_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6428
    ADD CONSTRAINT commconcept_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6429 6429

  
6430 6430

  
6431 6431
--
......
6449 6449
--
6450 6450

  
6451 6451
ALTER TABLE ONLY commdetermination
6452
    ADD CONSTRAINT commdetermination_commauthority_id_fkey FOREIGN KEY (commauthority_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6452
    ADD CONSTRAINT commdetermination_commauthority_id_fkey FOREIGN KEY (commauthority_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6453 6453

  
6454 6454

  
6455 6455
--
......
6485 6485

  
6486 6486

  
6487 6487
--
6488
-- Name: commname_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6488
-- Name: commname_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6489 6489
--
6490 6490

  
6491 6491
ALTER TABLE ONLY commname
6492
    ADD CONSTRAINT commname_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6492
    ADD CONSTRAINT commname_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6493 6493

  
6494 6494

  
6495 6495
--
......
6517 6517

  
6518 6518

  
6519 6519
--
6520
-- Name: commstatus_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6520
-- Name: commstatus_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6521 6521
--
6522 6522

  
6523 6523
ALTER TABLE ONLY commstatus
6524
    ADD CONSTRAINT commstatus_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6524
    ADD CONSTRAINT commstatus_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6525 6525

  
6526 6526

  
6527 6527
--
......
6557 6557

  
6558 6558

  
6559 6559
--
6560
-- Name: coordinates_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6560
-- Name: coordinates_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6561 6561
--
6562 6562

  
6563 6563
ALTER TABLE ONLY coordinates
6564
    ADD CONSTRAINT coordinates_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6564
    ADD CONSTRAINT coordinates_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6565 6565

  
6566 6566

  
6567 6567
--
......
6573 6573

  
6574 6574

  
6575 6575
--
6576
-- Name: covermethod_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6576
-- Name: covermethod_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6577 6577
--
6578 6578

  
6579 6579
ALTER TABLE ONLY covermethod
6580
    ADD CONSTRAINT covermethod_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6580
    ADD CONSTRAINT covermethod_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6581 6581

  
6582 6582

  
6583 6583
--
......
6613 6613

  
6614 6614

  
6615 6615
--
6616
-- Name: location_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6616
-- Name: location_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6617 6617
--
6618 6618

  
6619 6619
ALTER TABLE ONLY location
6620
    ADD CONSTRAINT location_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6620
    ADD CONSTRAINT location_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6621 6621

  
6622 6622

  
6623 6623
--
......
6661 6661

  
6662 6662

  
6663 6663
--
6664
-- Name: locationevent_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6664
-- Name: locationevent_soiltaxon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6665 6665
--
6666 6666

  
6667 6667
ALTER TABLE ONLY locationevent
6668
    ADD CONSTRAINT locationevent_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
6668
    ADD CONSTRAINT locationevent_soiltaxon_id_fkey FOREIGN KEY (soiltaxon_id) REFERENCES soiltaxon(soiltaxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
6669 6669

  
6670 6670

  
6671 6671
--
6672
-- Name: locationevent_soiltaxon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6672
-- Name: locationevent_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6673 6673
--
6674 6674

  
6675 6675
ALTER TABLE ONLY locationevent
6676
    ADD CONSTRAINT locationevent_soiltaxon_id_fkey FOREIGN KEY (soiltaxon_id) REFERENCES soiltaxon(soiltaxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
6676
    ADD CONSTRAINT locationevent_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;
6677 6677

  
6678 6678

  
6679 6679
--
......
6749 6749

  
6750 6750

  
6751 6751
--
6752
-- Name: method_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6752
-- Name: method_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
6753 6753
--
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff