--
-- PostgreSQL database dump
--

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;

--
-- Name: accesslevel; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE accesslevel AS ENUM (
    'private',
    'metadata only',
    'data by request',
    'public'
);


--
-- Name: coordinatesource; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE coordinatesource AS ENUM (
    'source data',
    'GPS',
    'georeferencing'
);


--
-- Name: TYPE coordinatesource; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TYPE coordinatesource IS 'From <https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore_data_dictionary#coordinateSource>';


--
-- Name: establishmentmeans_dwc; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE establishmentmeans_dwc AS ENUM (
    'cultivated',
    'wild',
    'native',
    'exotic',
    'invasive',
    'escaped from captivity'
);


--
-- Name: TYPE establishmentmeans_dwc; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TYPE establishmentmeans_dwc IS 'See <http://rs.tdwg.org/dwc/terms/#establishmentMeans>';


--
-- Name: growthform; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE growthform AS ENUM (
    'tree',
    'shrub',
    'liana',
    'vine',
    'herb',
    'hemiepiphyte',
    'epiphyte',
    'grass',
    'forb',
    'moss',
    'lichen',
    'fungus',
    'floating aquatic',
    'submerged aquatic'
);


--
-- Name: higher_plant_group; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE higher_plant_group AS ENUM (
    'all',
    'bryophytes',
    'ferns and allies',
    'flowering plants',
    'gymnosperms (conifers)',
    'gymnosperms (non-conifer)'
);


--
-- Name: observationtype; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE observationtype AS ENUM (
    'plot',
    'specimen'
);


--
-- Name: occurrencestatus_dwc; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE occurrencestatus_dwc AS ENUM (
    'present',
    'absent',
    'common',
    'irregular',
    'rare',
    'doubtful'
);


--
-- Name: placerank; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE placerank AS ENUM (
    'continent',
    'waterBody',
    'islandGroup',
    'island',
    'country',
    'territory',
    'region',
    'stateProvince',
    'county',
    'municipality',
    'village',
    'site'
);


--
-- Name: TYPE placerank; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TYPE placerank IS 'county = parish, canton
municipality = city

From <http://rs.tdwg.org/dwc/terms/#dcindex#dcterms:Location>, <http://vegbank.org/vegbank/views/dba_fielddescription_detail.jsp?view=detail&wparam=1415&entity=dba_fielddescription&params=1415>';


--
-- Name: rankedplacename; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE rankedplacename AS (
	rank placerank,
	verbatimrank text,
	placename text
);


--
-- Name: taxonrank; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE taxonrank AS ENUM (
    'unknown',
    'suprageneric',
    'domain',
    'superkingdom',
    'kingdom',
    'subkingdom',
    'infrakingdom',
    'superphylum',
    'phylum',
    'subphylum',
    'infraphylum',
    'superclass',
    'class',
    'subclass',
    'infraclass',
    'superorder',
    'order',
    'suborder',
    'infraorder',
    'family group',
    'superfamily',
    'family',
    'subfamily',
    'infrafamily',
    'family subdivision',
    'supertribe',
    'tribe',
    'subtribe',
    'infratribe',
    'genus group',
    'genus',
    'subgenus',
    'infragenus',
    'genus subdivision',
    'section',
    'subsection',
    'series',
    'subseries',
    'infrageneric',
    'species aggregate',
    'species group',
    'species',
    'subspecies',
    'subspecific aggregate',
    'below subspecies',
    'infraspecies',
    'biovariety',
    'pathovariety',
    'variety',
    'subvariety',
    'subsubvariety',
    'forma',
    'subforma',
    'subsubforma',
    'special forma',
    'infraspecific',
    'candidate',
    'cultivated plants',
    'cultivar',
    'convar',
    'grex',
    'cultivar group',
    'graft-chimaera',
    'denomination class'
);


--
-- Name: TYPE taxonrank; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TYPE taxonrank IS 'From <http://www.tdwg.org/standards/117/download/>';


--
-- Name: rankedtaxonname; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE rankedtaxonname AS (
	rank taxonrank,
	verbatimrank text,
	taxonname text
);


--
-- Name: relationship; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE relationship AS ENUM (
    'is congruent to',
    'is not congruent to',
    'is included in',
    'is not included in',
    'overlaps',
    'does not overlap',
    'is child taxon of',
    'is anamorph of',
    'is teleomorph of',
    'is hybrid child of',
    'is ambiregnal of',
    'is vernacular for'
);


--
-- Name: role; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE role AS ENUM (
    'unknown',
    'advisor',
    'author',
    'co-principal investigator',
    'collector',
    'computer',
    'contact',
    'contributor',
    'custodian/steward',
    'editor',
    'identifier',
    'originator',
    'performer',
    'principal investigator',
    'recipient',
    'reviewer',
    'technician'
);


--
-- Name: TYPE role; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TYPE role IS 'From <http://vegbank.org/vegbank/views/dba_fielddescription_detail.jsp?view=detail&wparam=1331&entity=dba_fielddescription&params=1331>, <http://vegbank.org/vegbank/views/dba_tabledescription_detail.jsp?view=detail&wparam=projectcontributor&entity=dba_tabledescription&where=where_tablename#ROLE_ID>, and misc terms.';


--
-- Name: sourcetype; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE sourcetype AS ENUM (
    'herbarium',
    'primary database',
    'aggregator',
    'book',
    'article',
    'chapter',
    'conference proceedings',
    'dissertation',
    'edited book',
    'generic',
    'journal',
    'manuscript',
    'personal communication',
    'presentation',
    'report',
    'thesis',
    'website'
);


--
-- Name: TYPE sourcetype; Type: COMMENT; Schema: public; Owner: -
--

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>';


--
-- Name: taxonclass; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE taxonclass AS ENUM (
    'tree',
    'shrub',
    'liana',
    'vine',
    'herb',
    'hemiepiphyte',
    'epiphyte',
    'grass',
    'forb',
    'moss',
    'lichen',
    'fungus',
    'floating aquatic',
    'submerged aquatic',
    'cultivated',
    'wild',
    'native',
    'exotic',
    'invasive',
    'escaped from captivity',
    'dominant',
    'vascular',
    'woody'
);


--
-- Name: TYPE taxonclass; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TYPE taxonclass IS '= growthform + establishmentmeans_dwc + some others';


--
-- Name: taxonomic_status; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE taxonomic_status AS ENUM (
    'No opinion',
    'Accepted',
    'Synonym',
    'Illegitimate',
    'Invalid'
);


--
-- Name: TYPE taxonomic_status; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TYPE taxonomic_status IS 'See <http://tnrs.iplantcollaborative.org/instructions.html#Status>';


--
-- Name: _cm_to_m(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _cm_to_m(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1/100.
$_$;


--
-- Name: _filter_genus(text); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _filter_genus(value text) RETURNS text
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT (CASE WHEN $1 ~ '\d' THEN NULL ELSE $1 END)
$_$;


--
-- Name: _fraction_to_percent(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _fraction_to_percent(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1*100.
$_$;


--
-- Name: _ft_to_m(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _ft_to_m(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT _in_to_m($1*12)
$_$;


--
-- Name: _ha_to_m2(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _ha_to_m2(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1*10000.
$_$;


--
-- Name: _has_taxonomic_name(taxonrank); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _has_taxonomic_name(rank taxonrank) RETURNS boolean
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1 >= 'family'
$_$;


--
-- Name: _in_to_m(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _in_to_m(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1*2.54/100.
$_$;


--
-- Name: _km_to_m(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _km_to_m(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1*1000.
$_$;


--
-- Name: _locationnarrative_is_cultivated(text); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _locationnarrative_is_cultivated(locationnarrative text) RETURNS boolean
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT bool_or(value)
FROM
(VALUES
      (NULLIF($1 LIKE '%cultivated%', false))
    , (NULLIF($1 LIKE '%cultivad%', false))
    , (NULLIF($1 LIKE '%ornamental%', false))
    , (NULLIF($1 LIKE '%garden%', false))
    , (NULLIF($1 LIKE '%jardin%', false))
    , (NULLIF($1 LIKE '%jard?n%', false))
    , (NULLIF($1 LIKE '%jardim%', false))
    , (NULLIF($1 LIKE '%plantation%', false))
    , (NULLIF($1 LIKE '%plantacion%', false))
    , (NULLIF($1 LIKE '%plantaci?n%', false))
    , (NULLIF($1 LIKE '%universit%', false))
    , (NULLIF($1 LIKE '%universidad%', false))
    , (NULLIF($1 LIKE '%campus%' , false))
    , (NULLIF($1 LIKE '%urban%', false))
    , (NULLIF($1 LIKE '%greenhouse%', false))
    , (NULLIF($1 LIKE '%arboretum%', false))
    , (NULLIF($1 LIKE '%farm%', false))
    , (NULLIF($1 LIKE '%weed%', false))
    , (NULLIF($1 LIKE '%corn field%', false))
)
AS v (value)
$_$;


--
-- Name: _m2_to_ha(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _m2_to_ha(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1/10000.
$_$;


--
-- Name: _m_to_cm(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _m_to_cm(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1*100.
$_$;


--
-- Name: _m_to_km(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _m_to_km(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1/1000.
$_$;


--
-- Name: _mm_to_m(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _mm_to_m(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1/1000.
$_$;


--
-- Name: _or(boolean, boolean, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _or("0" boolean DEFAULT NULL::boolean, "1" boolean DEFAULT NULL::boolean, "2" boolean DEFAULT NULL::boolean, "3" boolean DEFAULT NULL::boolean, "4" boolean DEFAULT NULL::boolean) RETURNS boolean
    LANGUAGE sql IMMUTABLE
    AS $_$
SELECT bool_or(value)
FROM
(VALUES
      ($1)
    , ($2)
    , ($3)
    , ($4)
    , ($5)
)
AS v (value)
$_$;


--
-- Name: FUNCTION _or("0" boolean, "1" boolean, "2" boolean, "3" boolean, "4" boolean); Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON FUNCTION _or("0" boolean, "1" boolean, "2" boolean, "3" boolean, "4" boolean) IS '_or() ignores NULL values, while OR combines them with the other values to potentially convert false to NULL. OR should be used with required fields, and _or() with optional fields.';


--
-- Name: _percent_to_fraction(double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _percent_to_fraction(value double precision) RETURNS double precision
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1/100.
$_$;


--
-- Name: _taxon_family_require_std(text); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _taxon_family_require_std(family text) RETURNS text
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT (CASE WHEN
    lower($1) LIKE '%aceae'
    OR lower($1) IN (
        'compositae',
        'cruciferae',
        'gramineae',
        'labiatae',
        'leguminosae',
        'palmae',
        'umbelliferae'
    )
THEN $1 ELSE NULL END)
$_$;


--
-- Name: _taxonlabel_set_matched_label_id(integer, integer, double precision); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _taxonlabel_set_matched_label_id(taxonlabel_id integer, matched_label_id integer, matched_label_fit_fraction double precision DEFAULT NULL::double precision) RETURNS integer
    LANGUAGE plpgsql
    AS $$
BEGIN
    -- Use EXECUTE to avoid caching query plan
    EXECUTE '
    UPDATE taxonlabel SET
      matched_label_id = '||quote_nullable(matched_label_id)||'
    , matched_label_fit_fraction = '
        ||quote_nullable(matched_label_fit_fraction)||'
    WHERE taxonlabel_id = '||quote_nullable(taxonlabel_id)||'
    ';
    
    RETURN taxonlabel_id;
END;
$$;


--
-- Name: _taxonlabel_set_parent_id(integer, integer); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _taxonlabel_set_parent_id(taxonlabel_id integer, parent_id integer) RETURNS integer
    LANGUAGE plpgsql
    AS $$
BEGIN
    -- Use EXECUTE to avoid caching query plan
    EXECUTE '
    UPDATE taxonlabel SET parent_id = '||quote_nullable(parent_id)||'
    WHERE taxonlabel_id = '||quote_nullable(taxonlabel_id)||'
    ';
    
    RETURN taxonlabel_id;
END;
$$;


--
-- Name: _taxonomic_name_is_epithet(taxonrank); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION _taxonomic_name_is_epithet(rank taxonrank) RETURNS boolean
    LANGUAGE sql IMMUTABLE STRICT
    AS $_$
SELECT $1 <= 'genus'
$_$;


SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: source; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE source (
    source_id integer NOT NULL,
    matched_source_id integer,
    parent_id integer,
    shortname text NOT NULL,
    citation text,
    sourcetype sourcetype,
    accesslevel accesslevel,
    accessconditions text,
    observationtype observationtype,
    title text,
    titlesuperior text,
    volume text,
    issue text,
    pagerange text,
    totalpages integer,
    publisher text,
    publicationplace text,
    isbn text,
    edition text,
    numberofvolumes integer,
    chapternumber integer,
    reportnumber integer,
    communicationtype text,
    degree text,
    url text,
    doi text,
    additionalinfo text,
    pubdate date,
    accessdate date,
    conferencedate date,
    datecreated date DEFAULT now() NOT NULL,
    createdby text,
    datelastmodified date DEFAULT now() NOT NULL,
    lastmodifiedby text,
    import_revision text
);


--
-- Name: datasource_publish(text, anyelement); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION datasource_publish(datasource text, schema_null anyelement DEFAULT NULL::source) RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
	live_datasource text := rm_version_suffix(datasource);
BEGIN
	PERFORM set_config('search_path', util.schema_ident(schema_null), true);
	
	-- don't datasource_rm() the datasource to publish!
	IF live_datasource = datasource THEN RETURN; END IF;
	
	BEGIN -- nested transaction
		PERFORM datasource_rm(live_datasource, schema_null);
		PERFORM datasource_rename(datasource, live_datasource, schema_null);
	EXCEPTION
		WHEN SQLSTATE /*successful_completion*/'00000' THEN NULL; -- need at least one WHEN clause
	END;
END;
$$;


--
-- Name: FUNCTION datasource_publish(datasource text, schema_null anyelement); Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON FUNCTION datasource_publish(datasource text, schema_null anyelement) IS 'secure against renamings of the public schema.

schema_null: identifies which schema''s tables to use. the default value is usually fine.
';


--
-- Name: datasource_rename(text, text, anyelement); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION datasource_rename(old text, new text, schema_null anyelement DEFAULT NULL::source) RETURNS void
    LANGUAGE sql
    AS $_$
SELECT set_config('search_path', util.schema_ident($3), true);
UPDATE source SET shortname = $2 WHERE shortname = $1;
$_$;


--
-- Name: FUNCTION datasource_rename(old text, new text, schema_null anyelement); Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON FUNCTION datasource_rename(old text, new text, schema_null anyelement) IS 'secure against renamings of the public schema.

schema_null: identifies which schema''s tables to use. the default value is usually fine.
';


--
-- Name: datasource_rm(text, anyelement); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION datasource_rm(datasource text, schema_null anyelement DEFAULT NULL::source) RETURNS void
    LANGUAGE sql
    AS $_$
SELECT set_config('search_path', util.schema_ident($2), true);
DELETE FROM source WHERE shortname = $1;
$_$;


--
-- Name: FUNCTION datasource_rm(datasource text, schema_null anyelement); Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON FUNCTION datasource_rm(datasource text, schema_null anyelement) IS 'secure against renamings of the public schema.

schema_null: identifies which schema''s tables to use. the default value is usually fine.

runtime:
ACAD:  30 s  :   27738 ms/   45,503 rows = 0.61 ms/row
MO  :  55 min: 3311962 ms/3,894,706 rows = 0.85 ms/row
GBIF: ~13 h  : 55,417,646 rows * 0.85 ms/row * 1 s/1000 ms * 1 h/3600 s = 13.1 h

to calculate runtime:
BEGIN;
SELECT datasource_rm(''datasource'');
ROLLBACK;
';


--
-- Name: delete_scrubbed_taxondeterminations(text); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION delete_scrubbed_taxondeterminations(datasource text) RETURNS void
    LANGUAGE sql
    AS $_$
DELETE FROM taxondetermination
USING taxonoccurrence
WHERE
    taxonoccurrence.source_id = source_by_shortname($1)
AND taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id
AND taxondetermination.source_id = source_by_shortname('TNRS')
$_$;


--
-- Name: locationevent__communities(integer); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION locationevent__communities(locationevent_id integer) RETURNS SETOF text
    LANGUAGE sql STABLE
    AS $_$
SELECT commdescription
FROM      commclass
LEFT JOIN commdetermination USING (commclass_id)
LEFT JOIN commconcept       USING (commconcept_id)
WHERE locationevent_id = $1
ORDER BY commdescription
$_$;


--
-- Name: locationevent__communities__array(integer); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION locationevent__communities__array(locationevent_id integer) RETURNS text[]
    LANGUAGE sql STABLE
    AS $_$
SELECT array_agg(locationevent__communities)
FROM locationevent__communities($1)
$_$;


--
-- Name: locationevent__contributors(integer); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION locationevent__contributors(locationevent_id integer) RETURNS SETOF text
    LANGUAGE sql STABLE
    AS $_$
SELECT fullname
FROM locationeventcontributor
LEFT JOIN party USING (party_id)
WHERE locationevent_id = $1
ORDER BY fullname
$_$;


--
-- Name: locationevent__contributors__array(integer); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION locationevent__contributors__array(locationevent_id integer) RETURNS text[]
    LANGUAGE sql STABLE
    AS $_$
SELECT array_agg(locationevent__contributors)
FROM locationevent__contributors($1)
$_$;


--
-- Name: locationevent__pull_forward_from_parent(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION locationevent__pull_forward_from_parent() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
	parent locationevent;
BEGIN
	SELECT * INTO parent FROM locationevent WHERE locationevent_id = new.parent_id;
	
	IF new.location_id IS NULL THEN new.location_id = parent.location_id; END IF;
	
	RETURN new;
END;
$$;


--
-- Name: FUNCTION locationevent__pull_forward_from_parent(); Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON FUNCTION locationevent__pull_forward_from_parent() IS 'see wiki.vegpath.org/Pull-forward';


--
-- Name: make_family_higher_plant_group(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION make_family_higher_plant_group() RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
    source_id_ integer :=
        (SELECT source_id FROM source WHERE shortname = 'NCBI');
    row_ higher_plant_group_nodes%ROWTYPE;
BEGIN
    TRUNCATE family_higher_plant_group;
    
    FOR row_ IN
        SELECT * FROM higher_plant_group_nodes
        ORDER BY higher_plant_group, node_name
    LOOP
        DECLARE
            higher_plant_group_id integer := (
                SELECT taxonlabel_id FROM taxonlabel
                WHERE source_id = source_id_
                AND taxonomicname = row_.node_name
            );
            family text;
        BEGIN
            FOR family IN
                SELECT taxonepithet
                FROM taxonlabel_relationship
                JOIN taxonlabel ON taxonlabel_id = descendant_id
                WHERE ancestor_id = higher_plant_group_id
                AND rank = 'family'
                AND source_id = source_id_
                AND taxonepithet IS NOT NULL
            LOOP
                BEGIN
                    INSERT INTO family_higher_plant_group
                    VALUES (family, row_.higher_plant_group)
                    ;
                EXCEPTION
                    WHEN unique_violation THEN NULL;
                END;
            END LOOP;
        END;
    END LOOP;
END;
$$;


--
-- Name: party_source_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION party_source_id_self_ref() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF new.party_id IS NULL THEN -- prepopulate party_id
        new.party_id = nextval('party_party_id_seq'::regclass);
    END IF;
    IF new.source_id = 0 THEN -- make self-source
        new.source_id = new.party_id;
    END IF;
    RETURN new;
END;
$$;


--
-- Name: place_matched_place_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION place_matched_place_id_self_ref() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF new.place_id IS NULL THEN -- prepopulate place_id
        new.place_id = nextval('place_place_id_seq'::regclass);
    END IF;
    IF new.matched_place_id = 0 THEN -- make self-source
        new.matched_place_id = new.place_id;
    END IF;
    RETURN new;
END;
$$;


--
-- Name: place; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE place (
    place_id integer NOT NULL,
    source_id integer NOT NULL,
    canon_place_id integer,
    matched_place_id integer,
    coordinates_id integer,
    placename_id integer,
    continent text,
    country text,
    stateprovince text,
    county text,
    description text,
    geovalid boolean DEFAULT false NOT NULL,
    distance_to_country_m double precision,
    distance_to_state_m double precision,
    distance_to_county_m double precision,
    CONSTRAINT place_required_key CHECK ((((((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)))
);


--
-- Name: TABLE place; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE place IS 'The full path to a place. Can be either verbatim or accepted. For accepted names, points to the identified place.

To use a custom hierarchy of placenames with no explicit column, point to the lowest-rank placename in placename_id.';


--
-- Name: COLUMN place.matched_place_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN place.matched_place_id IS 'The closest match to this place. Places should be linked in a three-level hierarchy of datasource place -> verbatim place -> accepted place.

An accepted place should point to itself in this field. This will happen automatically by setting it to the special value 0.';


--
-- Name: place_set_canon_place_id(place, integer, boolean); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION place_set_canon_place_id(new place, old_matched_place_id integer DEFAULT NULL::integer, is_update boolean DEFAULT false) RETURNS place
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF NOT is_update
        OR new.matched_place_id IS DISTINCT FROM old_matched_place_id THEN
        IF new.matched_place_id IS NOT NULL THEN
            IF new.matched_place_id = new.place_id THEN -- self-source
                new.canon_place_id := new.place_id; -- make self-source
            ELSE -- propagate from matched place
                new.canon_place_id := (
                    SELECT canon_place_id
                    FROM place
                    WHERE place_id = new.matched_place_id
                );
            END IF;
            
            IF is_update THEN
                -- Update canon_place_id on places that resolve to this place
                UPDATE place
                SET canon_place_id = new.canon_place_id
                WHERE matched_place_id = new.place_id
                AND place_id != new.place_id -- no infinite recursion
                ;
            END IF;
        ELSE -- no matched place
            new.canon_place_id := new.place_id; -- make self-source
        END IF;
    END IF;
    
    RETURN new;
END;
$$;


--
-- Name: place_set_canon_place_id_on_insert(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION place_set_canon_place_id_on_insert() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    new := place_set_canon_place_id(new);
    
    RETURN new;
END;
$$;


--
-- Name: place_set_canon_place_id_on_update(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION place_set_canon_place_id_on_update() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    new := place_set_canon_place_id(new, old.matched_place_id, true);
    
    RETURN new;
END;
$$;


--
-- Name: placename_update_ancestors(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION placename_update_ancestors() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    -- Delete existing ancestors
    DELETE FROM placename_ancestor WHERE placename_id = new.placename_id;
    
    IF new.parent_id IS NOT NULL THEN
        -- Copy parent's ancestors to this node's ancestors
        INSERT
        INTO placename_ancestor
        (placename_id, ancestor_id)
        SELECT
            new.placename_id, ancestor_id
        FROM placename_ancestor
        WHERE placename_id = new.parent_id
        ;
    END IF;
    
    -- Add "ancestor" for this node
    /* This is useful for queries, because you don't have to separately test if
    the leaf node is the one you're looking for, in addition to that leaf node's
    ancestors. */
    INSERT
    INTO placename_ancestor
    (placename_id, ancestor_id)
    VALUES (new.placename_id, new.placename_id)
    ;
    
    -- Tell immediate children to update their ancestors lists, which will
    -- recursively tell all descendants
    UPDATE placename
    SET placename_id = placename_id -- need at least one SET statement
    -- Add COALESCE() to enable using placename_unique index for lookup
    WHERE COALESCE(parent_id, 2147483647) = new.placename_id
    AND placename_id != new.placename_id -- avoid infinite recursion
    ;
    
    /* Note: We don't need an ON DELETE trigger to update the descendants'
    ancestors when a node is deleted, because the placename.placename_parent_id
    foreign key is set to ON DELETE CASCADE, which just removes all the
    descendants anyway. */
    
    RETURN new;
END;
$$;


--
-- Name: plantobservation_aggregateoccurrence_count_1(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION plantobservation_aggregateoccurrence_count_1() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    UPDATE aggregateoccurrence
    SET count = GREATEST(COALESCE(count, 0), 1) -- at least 1
    WHERE aggregateoccurrence_id = new.aggregateoccurrence_id
    ;
    RETURN new;
END;
$$;


--
-- Name: rm_version_suffix(text); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION rm_version_suffix(name text) RETURNS text
    LANGUAGE sql IMMUTABLE
    AS $_$
SELECT regexp_replace($1, '\..*$', '')
$_$;


--
-- Name: source_by_shortname(text); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION source_by_shortname(shortname text) RETURNS integer
    LANGUAGE sql STABLE STRICT
    AS $_$
SELECT source_id FROM source WHERE shortname = $1 LIMIT 1
$_$;


--
-- Name: sourcename_set_matched_source_id(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION sourcename_set_matched_source_id() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF new.matched_source_id IS NULL THEN -- populate matched_source_id
        new.matched_source_id :=
            (SELECT source_id FROM source WHERE shortname = new.name);
    END IF;
    RETURN new;
END;
$$;


--
-- Name: sync_analytical_stem_to_view(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION sync_analytical_stem_to_view() RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
    analytical_plot_def text := NULL;
    analytical_specimen_def text := NULL;
    provider_count_view_def text := NULL;
    range_modeling_input_def text := NULL;
BEGIN
    -- Save and drop dependent objects
    BEGIN
        analytical_plot_def :=
            'CREATE OR REPLACE VIEW analytical_plot AS '
            ||pg_get_viewdef('analytical_plot');
        DROP VIEW analytical_plot;
    EXCEPTION
        WHEN undefined_table THEN NULL;
    END;
    BEGIN
        analytical_specimen_def :=
            'CREATE OR REPLACE VIEW analytical_specimen AS '
            ||pg_get_viewdef('analytical_specimen');
        DROP VIEW analytical_specimen;
    EXCEPTION
        WHEN undefined_table THEN NULL;
    END;
    BEGIN
        provider_count_view_def :=
            'CREATE OR REPLACE VIEW provider_count_view AS '
            ||pg_get_viewdef('provider_count_view');
        DROP VIEW provider_count_view;
    EXCEPTION
        WHEN undefined_table THEN NULL;
    END;
    BEGIN
        range_modeling_input_def :=
            'CREATE OR REPLACE VIEW range_modeling_input AS '
            ||pg_get_viewdef('range_modeling_input');
        DROP VIEW range_modeling_input;
    EXCEPTION
        WHEN undefined_table THEN NULL;
    END;
    
    DROP TABLE IF EXISTS analytical_stem;
    CREATE TABLE analytical_stem AS SELECT * FROM analytical_stem_view LIMIT 0;
    
    GRANT SELECT ON TABLE analytical_stem TO bien_read;
    GRANT SELECT ON TABLE analytical_stem_view TO bien_read;
    
    ALTER TABLE analytical_stem ADD FOREIGN KEY (datasource) REFERENCES source (shortname) ON UPDATE CASCADE ON DELETE CASCADE;
    
    ALTER TABLE analytical_stem ALTER COLUMN "datasource" SET NOT NULL;
    ALTER TABLE analytical_stem ALTER COLUMN "locationID" SET NOT NULL;
    
    CREATE INDEX ON analytical_stem ("datasource", "occurrenceID");
    CREATE INDEX ON analytical_stem ("datasource", "institutionCode", "collectionCode", "catalogNumber");
    CREATE INDEX ON analytical_stem ("datasource", "projectID", "locationID", "dateCollected");
    
    -- Re-create dependent objects
    IF analytical_plot_def IS NOT NULL THEN
        EXECUTE analytical_plot_def;
        GRANT SELECT ON TABLE analytical_plot TO bien_read;
    END IF;
    IF analytical_specimen_def IS NOT NULL THEN
        EXECUTE analytical_specimen_def;
        GRANT SELECT ON TABLE analytical_specimen TO bien_read;
    END IF;
    IF provider_count_view_def IS NOT NULL THEN
        EXECUTE provider_count_view_def;
        GRANT SELECT ON TABLE provider_count_view TO bien_read;
        GRANT SELECT ON TABLE provider_count_view TO public_;
    END IF;
    IF range_modeling_input_def IS NOT NULL THEN
        EXECUTE range_modeling_input_def;
        GRANT SELECT ON TABLE range_modeling_input TO bien_read;
    END IF;
END;
$$;


--
-- Name: sync_geoscrub_input_to_view(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION sync_geoscrub_input_to_view() RETURNS void
    LANGUAGE sql
    AS $$
DROP TABLE IF EXISTS geoscrub_input;
CREATE TABLE geoscrub_input AS SELECT * FROM geoscrub_input_view;

GRANT SELECT ON TABLE geoscrub_input TO bien_read;
GRANT SELECT ON TABLE geoscrub_input_view TO bien_read;
$$;


--
-- Name: sync_provider_count_to_view(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION sync_provider_count_to_view() RETURNS void
    LANGUAGE sql
    AS $$
DROP TABLE IF EXISTS provider_count;
CREATE TABLE provider_count AS SELECT * FROM provider_count_view LIMIT 0;

GRANT SELECT ON TABLE provider_count TO bien_read;
GRANT SELECT ON TABLE provider_count TO public_;
GRANT SELECT ON TABLE provider_count_view TO bien_read;
GRANT SELECT ON TABLE provider_count_view TO public_;

ALTER TABLE provider_count ADD PRIMARY KEY (dataprovider, dataset);
$$;


--
-- Name: sync_taxon_trait_to_view(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION sync_taxon_trait_to_view() RETURNS void
    LANGUAGE sql
    AS $$
DROP TABLE IF EXISTS taxon_trait;
CREATE TABLE taxon_trait AS SELECT * FROM taxon_trait_view LIMIT 0;

GRANT SELECT ON TABLE taxon_trait TO bien_read;
GRANT SELECT ON TABLE taxon_trait_view TO bien_read;

ALTER TABLE taxon_trait ALTER COLUMN "scientificName" SET NOT NULL;
ALTER TABLE taxon_trait ALTER COLUMN "measurementType" SET NOT NULL;

CREATE INDEX ON taxon_trait ("scientificName", "measurementType" );
$$;


--
-- Name: taxondetermination_set_iscurrent(integer); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxondetermination_set_iscurrent(taxonoccurrence_id_ integer) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    UPDATE taxondetermination SET iscurrent = false
    WHERE taxonoccurrence_id = taxonoccurrence_id_ AND iscurrent;
    
    UPDATE taxondetermination SET iscurrent = true
    WHERE taxondetermination_id = (
        SELECT taxondetermination_id FROM taxondetermination
        WHERE taxonoccurrence_id = taxonoccurrence_id_
        ORDER BY
            -- Scrubbed determinations must come first for scrub.make to work
              COALESCE(determinationtype = 'accepted', false) DESC/*true first*/
            , COALESCE(determinationtype = 'matched', false) DESC/*true first*/
            , isoriginal/*false first*/
            , determinationdate DESC NULLS LAST
        LIMIT 1
    );
    
    UPDATE taxondetermination SET is_datasource_current = false
    WHERE taxonoccurrence_id = taxonoccurrence_id_ AND is_datasource_current;
    
    UPDATE taxondetermination SET is_datasource_current = true
    WHERE taxondetermination_id = (
        SELECT taxondetermination_id FROM taxondetermination
        WHERE taxonoccurrence_id = taxonoccurrence_id_
        AND determinationtype NOT IN ('accepted', 'matched')
        ORDER BY
            isoriginal/*false first*/
            , determinationdate DESC NULLS LAST
        LIMIT 1
    );
END;
$$;


--
-- Name: taxondetermination_set_iscurrent_on_delete(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxondetermination_set_iscurrent_on_delete() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    BEGIN
        PERFORM taxondetermination_set_iscurrent(old.taxonoccurrence_id);
    EXCEPTION
        WHEN foreign_key_violation THEN NULL; -- cascading delete
    END;
    
    RETURN old;
END;
$$;


--
-- Name: taxondetermination_set_iscurrent_on_insert(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxondetermination_set_iscurrent_on_insert() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    PERFORM taxondetermination_set_iscurrent(new.taxonoccurrence_id);
    RETURN new;
END;
$$;


--
-- Name: taxonlabel_0_matched_label_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_0_matched_label_id_self_ref() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF new.taxonlabel_id IS NULL THEN -- prepopulate taxonlabel_id
        new.taxonlabel_id = nextval('taxonlabel_taxonlabel_id_seq'::regclass);
    END IF;
    IF new.matched_label_id = 0 THEN -- make self-source
        new.matched_label_id = new.taxonlabel_id;
    END IF;
    RETURN new;
END;
$$;


--
-- Name: taxonlabel_2_set_canon_label_id_on_insert(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_2_set_canon_label_id_on_insert() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    new := taxonlabel_set_canon_label_id(new);
    
    RETURN new;
END;
$$;


--
-- Name: taxonlabel_2_set_canon_label_id_on_update(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_2_set_canon_label_id_on_update() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    new := taxonlabel_set_canon_label_id(new, old.matched_label_id, true);
    
    RETURN new;
END;
$$;


--
-- Name: taxonlabel_3_parent_id_avoid_self_ref(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_3_parent_id_avoid_self_ref() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    new.parent_id = nullif(new.parent_id, new.taxonlabel_id);
    RETURN new;
END;
$$;


--
-- Name: taxonlabel; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonlabel (
    taxonlabel_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    taxonstatus taxonomic_status,
    canon_label_id integer,
    matched_label_id integer,
    parent_id integer,
    taxonepithet text,
    rank taxonrank,
    taxonomicname text,
    CONSTRAINT taxonlabel_required_key CHECK ((((sourceaccessioncode IS NOT NULL) OR (taxonepithet IS NOT NULL)) OR (taxonomicname IS NOT NULL)))
);


--
-- Name: TABLE taxonlabel; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE taxonlabel IS 'A taxon label defined by an entity. Can be at any level in the taxonomic hierarchy. Can be either verbatim or accepted.

"A taxon (plural: taxa) is a group of one (or more) populations of organism(s), which a taxonomist adjudges to be a unit" (http://en.wikipedia.org/wiki/Taxon)

Note that taxonepithet stores only one rank (e.g. family) of the full taxonomic name. The higher-level ranks are stored in the taxon label''s chain of parent_id ancestors.

Equivalent to VegBank''s plantConcept and plantName tables, plus plantParent_ID and plantLevel from plantStatus.';


--
-- Name: COLUMN taxonlabel.source_id; Type: COMMENT; Schema: public; Owner: -
--

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


--
-- Name: COLUMN taxonlabel.sourceaccessioncode; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel.sourceaccessioncode IS 'The datasource''s identifier for the taxonlabel.';


--
-- Name: COLUMN taxonlabel.canon_label_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel.canon_label_id IS 'The canonical taxonlabel for this taxonlabel.';


--
-- Name: COLUMN taxonlabel.matched_label_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel.matched_label_id IS 'The taxonlabel containing the closest match to this taxonlabel. taxonlabels should be linked in a four-level hierarchy of datasource label -> parsed label -> matched label -> accepted label. A previously-accepted name''s label should be further linked to the synonym that has replaced it.

To indicate a synonym between taxonlabels of different sources, choose one taxonlabel to be authoritative and point the other taxonlabel to it using this field.

An accepted name should point to itself in this field. This will happen automatically by setting it to the special value 0.';


--
-- Name: COLUMN taxonlabel.parent_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel.parent_id IS 'The parent taxonlabel. Note that while a taxon *name* may have multiple parents, a taxonlabel *instance* has only one, based on the creator''s opinion of where that taxonlabel goes in the taxonomic hierarchy.';


--
-- Name: COLUMN taxonlabel.taxonepithet; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel.taxonepithet IS 'The epithet of the taxon within its parent taxon. This is the lowest-rank portion of this taxonlabel''s full taxonomic name, if it has one.';


--
-- Name: COLUMN taxonlabel.rank; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel.rank IS 'The taxon''s level in the taxonomic hierarchy, standardized to a closed list. Even if you specify a custom verbatimrank in taxonverbatim, you should also specify a closest-match rank from the taxonrank closed list.';


--
-- Name: COLUMN taxonlabel.taxonomicname; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel.taxonomicname IS 'The concatenated taxonomic name which uniquely identifies this taxon, including the family and author of that name. Must be unique within the datasource.

Equivalent to Darwin Core''s scientificName.';


--
-- Name: taxonlabel_set_canon_label_id(taxonlabel, integer, boolean); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_set_canon_label_id(new taxonlabel, old_matched_label_id integer DEFAULT NULL::integer, is_update boolean DEFAULT false) RETURNS taxonlabel
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF NOT is_update
        OR new.matched_label_id IS DISTINCT FROM old_matched_label_id THEN
        IF new.matched_label_id IS NOT NULL THEN
            IF new.matched_label_id = new.taxonlabel_id THEN -- self-source
                new.canon_label_id := new.taxonlabel_id; -- make self-source
            ELSE -- propagate from matched label
                new.canon_label_id := (
                    SELECT canon_label_id
                    FROM taxonlabel
                    WHERE taxonlabel_id = new.matched_label_id
                );
            END IF;
            
            IF is_update THEN
                -- Update canon_label_id on labels that resolve to this label
                UPDATE taxonlabel
                SET canon_label_id = new.canon_label_id
                WHERE matched_label_id = new.taxonlabel_id
                AND taxonlabel_id != new.taxonlabel_id -- no infinite recursion
                ;
            END IF;
        ELSE -- no matched taxonlabel
            new.canon_label_id := new.taxonlabel_id; -- make self-source
        END IF;
    END IF;
    
    RETURN new;
END;
$$;


--
-- Name: taxonlabel_update_ancestors(taxonlabel, integer, integer); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_update_ancestors(new taxonlabel, parent_id_ integer, old_parent_id integer DEFAULT NULL::integer) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF parent_id_ IS DISTINCT FROM old_parent_id THEN
        DECLARE
            -- These include the parent itself
            old_ancestors integer[] := (
                SELECT array_agg(ancestor_id) FROM taxonlabel_relationship
                WHERE descendant_id = old_parent_id
            );
            new_ancestors integer[] := (
                SELECT array_agg(ancestor_id) FROM taxonlabel_relationship
                WHERE descendant_id = parent_id_
            );
            descendant_id_ taxonlabel_relationship.descendant_id%TYPE;
            ancestor_id_ taxonlabel_relationship.ancestor_id%TYPE;
        BEGIN
            FOR descendant_id_ IN -- also includes self
                SELECT descendant_id
                FROM taxonlabel_relationship
                WHERE ancestor_id = new.taxonlabel_id
            LOOP
                -- Delete old parent's ancestors
                DELETE FROM taxonlabel_relationship
                WHERE descendant_id = descendant_id_
                AND ancestor_id = ANY (old_ancestors)
                ;
                
                -- Add new parent's ancestors
                FOR ancestor_id_ IN
                    SELECT unnest(new_ancestors)
                LOOP
                    BEGIN
                        INSERT INTO taxonlabel_relationship
                        (descendant_id, ancestor_id)
                        SELECT descendant_id_, ancestor_id_
                        ;
                    EXCEPTION
                        WHEN unique_violation THEN
                            RAISE WARNING '%', SQLERRM;
                    END;
                END LOOP;
            END LOOP;
        END;
    END IF;
    
    /* Note: We don't need an ON DELETE trigger to update the descendants'
    ancestors when a node is deleted, because the
    taxonlabel_relationship.ancestor_id foreign key is ON DELETE CASCADE. */
END;
$$;


--
-- Name: taxonlabel_update_ancestors_on_insert(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_update_ancestors_on_insert() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    /* Add "ancestor" for this node. This is useful for queries, because you
    don't have to separately test if the leaf node is the one you're looking
    for, in addition to that leaf node's ancestors. */
    INSERT
    INTO taxonlabel_relationship
    (descendant_id, ancestor_id)
    VALUES (new.taxonlabel_id, new.taxonlabel_id)
    ;
    
    PERFORM taxonlabel_update_ancestors(new, new.parent_id);
    PERFORM taxonlabel_update_ancestors(new,
        NULLIF(new.matched_label_id, new.taxonlabel_id));
    
    RETURN new;
END;
$$;


--
-- Name: taxonlabel_update_ancestors_on_update(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION taxonlabel_update_ancestors_on_update() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    PERFORM taxonlabel_update_ancestors(new, new.parent_id, old.parent_id);
    PERFORM taxonlabel_update_ancestors(new,
        NULLIF(new.matched_label_id, new.taxonlabel_id),
        NULLIF(old.matched_label_id, old.taxonlabel_id));
    
    RETURN new;
END;
$$;


--
-- Name: concat(text); Type: AGGREGATE; Schema: public; Owner: -
--

CREATE AGGREGATE concat(text) (
    SFUNC = textcat,
    STYPE = text,
    INITCOND = ''
);


--
-- Name: address; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE address (
    address_id integer NOT NULL,
    party_id integer NOT NULL,
    organization_id integer,
    orgposition text,
    email text,
    street text,
    street2 text,
    city text,
    stateprovince text,
    postalcode text,
    country text,
    currentflag boolean,
    addressstartdate date
);


--
-- Name: address_address_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE address_address_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: address_address_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE address_address_id_seq OWNED BY address.address_id;


--
-- Name: address_address_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: aggregateoccurrence; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE aggregateoccurrence (
    aggregateoccurrence_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    taxonoccurrence_id integer,
    collectiondate date,
    cover_fraction double precision,
    linecover_m double precision,
    basalarea_m2 double precision,
    biomass_kg_m2 double precision,
    inferencearea_m2 double precision,
    count integer,
    stratum_id integer,
    coverindex_id integer,
    occurrencestatus_dwc occurrencestatus_dwc DEFAULT 'present'::occurrencestatus_dwc NOT NULL,
    method_id integer,
    notes text,
    CONSTRAINT aggregateoccurrence_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (taxonoccurrence_id IS NOT NULL)))
);


--
-- Name: TABLE aggregateoccurrence; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE aggregateoccurrence IS 'Equivalent to VegBank''s taxonimportance table.';


--
-- Name: COLUMN aggregateoccurrence.linecover_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN aggregateoccurrence.linecover_m IS 'The distance in m along which this occurrence intercepts a line subplot.';


--
-- Name: COLUMN aggregateoccurrence.occurrencestatus_dwc; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN aggregateoccurrence.occurrencestatus_dwc IS 'The extent to which the taxon is present. See <http://code.google.com/p/darwincore/wiki/Occurrence#occurrenceStatus>.';


--
-- Name: aggregateoccurrence_aggregateoccurrence_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE aggregateoccurrence_aggregateoccurrence_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: aggregateoccurrence_aggregateoccurrence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE aggregateoccurrence_aggregateoccurrence_id_seq OWNED BY aggregateoccurrence.aggregateoccurrence_id;


--
-- Name: aggregateoccurrence_aggregateoccurrence_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: analytical_stem; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE analytical_stem (
    datasource text NOT NULL,
    "institutionCode" text,
    "collectionCode" text,
    "catalogNumber" text,
    "occurrenceID" text,
    country text,
    "stateProvince" text,
    county text,
    locality text,
    "decimalLatitude" double precision,
    "decimalLongitude" double precision,
    "coordinateUncertaintyInMeters" double precision,
    "coordinateSource_bien" coordinatesource,
    "georeferenceProtocol_bien" text,
    geovalid_bien integer,
    "isNewWorld_bien" integer,
    "projectID" text,
    "locationID" text NOT NULL,
    "locationName" text,
    subplot text,
    "individualCode" text,
    "elevationInMeters" double precision,
    "plotArea_ha" double precision,
    "samplingProtocol" text,
    "temperature_C" double precision,
    precipitation_m double precision,
    stratum__name text,
    communities text[],
    plot__collectors text[],
    "recordedBy" text,
    "recordNumber" text,
    "dateCollected" date,
    family_verbatim text,
    "scientificName_verbatim" text,
    "identifiedBy" text,
    "dateIdentified" date,
    "identificationRemarks" text,
    family_matched text,
    "taxonName_matched" text,
    "scientificNameAuthorship_matched" text,
    "higherPlantGroup_bien" higher_plant_group,
    family text,
    genus text,
    "speciesBinomialWithMorphospecies" text,
    "taxonName" text,
    "scientificNameAuthorship" text,
    "growthForm" growthform,
    "reproductiveCondition" text,
    threatened_bien integer,
    cultivated_bien integer,
    "cultivatedBasis_bien" text,
    "occurrenceRemarks" text,
    "coverPercent" double precision,
    "diameterBreastHeight_cm" double precision,
    height_m double precision,
    tag text,
    "organismX_m" double precision,
    "organismY_m" double precision,
    "taxonOccurrenceID" text,
    "authorTaxonCode" text,
    "aggregateOrganismObservationID" text,
    "individualObservationID" text,
    "authorStemCode" text
);


--
-- Name: analytical_plot; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW analytical_plot AS
    SELECT analytical_stem.datasource, analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem.locality, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem."coordinateSource_bien", analytical_stem."georeferenceProtocol_bien", analytical_stem.geovalid_bien, analytical_stem."isNewWorld_bien", analytical_stem."projectID", analytical_stem."locationID", analytical_stem."locationName", analytical_stem.subplot, analytical_stem."individualCode", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem.stratum__name, analytical_stem.communities, analytical_stem.plot__collectors, analytical_stem."recordedBy", analytical_stem."recordNumber", analytical_stem."dateCollected", analytical_stem.family_verbatim, analytical_stem."scientificName_verbatim", analytical_stem."identifiedBy", analytical_stem."dateIdentified", analytical_stem."identificationRemarks", analytical_stem.family_matched, analytical_stem."taxonName_matched", analytical_stem."scientificNameAuthorship_matched", analytical_stem."higherPlantGroup_bien", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomialWithMorphospecies", analytical_stem."taxonName", analytical_stem."scientificNameAuthorship", analytical_stem."growthForm", analytical_stem."reproductiveCondition", analytical_stem.threatened_bien, analytical_stem.cultivated_bien, analytical_stem."cultivatedBasis_bien", analytical_stem."occurrenceRemarks", analytical_stem."coverPercent", analytical_stem."diameterBreastHeight_cm", analytical_stem.height_m, analytical_stem.tag, analytical_stem."organismX_m", analytical_stem."organismY_m", analytical_stem."taxonOccurrenceID", analytical_stem."authorTaxonCode", analytical_stem."aggregateOrganismObservationID", analytical_stem."individualObservationID", analytical_stem."authorStemCode", analytical_stem."institutionCode", analytical_stem."collectionCode", analytical_stem."catalogNumber", analytical_stem."occurrenceID" FROM analytical_stem;


--
-- Name: analytical_specimen; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW analytical_specimen AS
    SELECT analytical_stem.datasource, analytical_stem."institutionCode", analytical_stem."collectionCode", analytical_stem."catalogNumber", analytical_stem."occurrenceID", analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem.locality, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem."coordinateSource_bien", analytical_stem."georeferenceProtocol_bien", analytical_stem.geovalid_bien, analytical_stem."isNewWorld_bien", analytical_stem."elevationInMeters", analytical_stem."recordedBy", analytical_stem."recordNumber", analytical_stem."dateCollected", analytical_stem.family_verbatim, analytical_stem."scientificName_verbatim", analytical_stem."identifiedBy", analytical_stem."dateIdentified", analytical_stem."identificationRemarks", analytical_stem.family_matched, analytical_stem."taxonName_matched", analytical_stem."scientificNameAuthorship_matched", analytical_stem."higherPlantGroup_bien", analytical_stem.family, analytical_stem.genus, analytical_stem."taxonName", analytical_stem."scientificNameAuthorship", analytical_stem."reproductiveCondition", analytical_stem.cultivated_bien, analytical_stem."cultivatedBasis_bien", analytical_stem."occurrenceRemarks" FROM analytical_stem;


--
-- Name: coordinates; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE coordinates (
    coordinates_id integer NOT NULL,
    source_id integer NOT NULL,
    latitude_deg double precision NOT NULL,
    longitude_deg double precision NOT NULL,
    verbatimlatitude text,
    verbatimlongitude text,
    verbatimcoordinates text,
    footprintgeometry_dwc text,
    coordsaccuracy_m double precision
);


--
-- Name: COLUMN coordinates.footprintgeometry_dwc; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN coordinates.footprintgeometry_dwc IS 'DwC''s footprintWKT field. "A Well-Known Text (WKT) representation of the shape (footprint, geometry) that defines the Location" (http://rs.tdwg.org/dwc/terms/#footprintWKT).';


--
-- Name: COLUMN coordinates.coordsaccuracy_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN coordinates.coordsaccuracy_m IS 'Accuracy of latitude/longitude or footprint geometry, in meters. This should generally be at least 1 m, which is the accuracy of the best GPSes.';


--
-- Name: cultivated_family_locations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE cultivated_family_locations (
    family text NOT NULL,
    country text NOT NULL
);


--
-- Name: TABLE cultivated_family_locations; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE cultivated_family_locations IS 'from sftp://nimoy.nceas.ucsb.edu/home/bien/bien2_scripts/geoscrub/cultivated/cult_by_taxon/flag_by_taxa.inc';


--
-- Name: family_higher_plant_group; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE family_higher_plant_group (
    family text NOT NULL,
    higher_plant_group higher_plant_group
);


--
-- Name: location; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE location (
    location_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    parent_id integer,
    authorlocationcode text,
    accesslevel accesslevel,
    accessconditions text,
    sublocationxposition_m double precision,
    sublocationyposition_m double precision,
    iscultivated boolean,
    authorzone text,
    authordatum text,
    authorlocation text,
    locationnarrative text,
    azimuth double precision,
    shape text,
    area_m2 double precision,
    standsize text,
    placementmethod text,
    permanence boolean,
    layoutnarrative text,
    elevation_m double precision,
    elevationaccuracy_m double precision,
    elevationrange_m double precision,
    verbatimelevation text,
    slopeaspect_deg double precision,
    minslopeaspect_deg double precision,
    maxslopeaspect_deg double precision,
    slopegradient_fraction double precision,
    minslopegradient_fraction double precision,
    maxslopegradient_fraction double precision,
    topoposition text,
    landform text,
    surficialdeposits text,
    rocktype text,
    submitter_surname text,
    submitter_givenname text,
    submitter_email text,
    notespublic boolean,
    notesmgt boolean,
    revisions boolean,
    dateentered date DEFAULT now(),
    locationrationalenarrative text,
    CONSTRAINT location_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (authorlocationcode IS NOT NULL)))
);


--
-- Name: TABLE location; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE location IS 'Equivalent to VegBank''s plot table.';


--
-- Name: locationevent; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE locationevent (
    locationevent_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    accesslevel accesslevel,
    parent_id integer,
    location_id integer,
    project_id integer,
    stratum_id integer,
    authoreventcode text,
    previous_id integer,
    obsstartdate date,
    obsenddate date,
    dateaccuracy text,
    method_id integer,
    temperature_c double precision,
    precipitation_m double precision,
    autotaxoncover boolean,
    originaldata text,
    effortlevel text,
    floristicquality text,
    bryophytequality text,
    lichenquality text,
    locationeventnarrative text,
    landscapenarrative text,
    homogeneity text,
    phenologicaspect text,
    representativeness text,
    standmaturity text,
    successionalstatus text,
    basalarea double precision,
    hydrologicregime text,
    soilmoistureregime text,
    soildrainage text,
    watersalinity text,
    waterdepth_m double precision,
    shoredistance double precision,
    soildepth double precision,
    organicdepth double precision,
    soiltaxon_id integer,
    soiltaxonsrc text,
    percentbedrock double precision,
    percentrockgravel double precision,
    percentwood double precision,
    percentlitter double precision,
    percentbaresoil double precision,
    percentwater double precision,
    percentother double precision,
    nameother text,
    treeht double precision,
    shrubht double precision,
    fieldht double precision,
    nonvascularht double precision,
    submergedht double precision,
    treecover double precision,
    shrubcover double precision,
    fieldcover double precision,
    nonvascularcover double precision,
    floatingcover double precision,
    submergedcover double precision,
    dominantstratum text,
    growthform1type text,
    growthform2type text,
    growthform3type text,
    growthform1cover double precision,
    growthform2cover double precision,
    growthform3cover double precision,
    totalcover double precision,
    notespublic boolean,
    notesmgt boolean,
    revisions boolean,
    dateentered date DEFAULT now(),
    toptaxon1name text,
    toptaxon2name text,
    toptaxon3name text,
    toptaxon4name text,
    toptaxon5name text,
    numberoftaxa integer,
    CONSTRAINT locationevent_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (location_id IS NOT NULL)))
);


--
-- Name: TABLE locationevent; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE locationevent IS 'Equivalent to VegBank''s observation table.';


--
-- Name: locationplace; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE locationplace (
    locationplace_id integer NOT NULL,
    location_id integer NOT NULL,
    place_id integer NOT NULL,
    identifier_id integer
);


--
-- Name: TABLE locationplace; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE locationplace IS 'Equivalent to VegBank''s place table.';


--
-- Name: method; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE method (
    method_id integer NOT NULL,
    source_id integer NOT NULL,
    name text,
    description text,
    diameterheight_m double precision,
    mindiameter_m double precision,
    maxdiameter_m double precision,
    minheight_m double precision,
    maxheight_m double precision,
    observationtype text,
    observationmeasure text,
    covermethod_id integer,
    samplingfactor double precision DEFAULT 1 NOT NULL,
    coverbasis text,
    stemsamplemethod text,
    shape text,
    length_m double precision,
    width_m double precision,
    radius_m double precision,
    area_m2 double precision,
    samplearea_m2 double precision,
    subplotspacing_m double precision,
    subplotmethod_id integer,
    pointsperline integer,
    CONSTRAINT method_required_key CHECK ((((name IS NOT NULL) OR (description IS NOT NULL)) OR (observationmeasure IS NOT NULL)))
);


--
-- Name: TABLE method; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE method IS 'A method for sampling and aggregating plants. Replaces VegBank''s stratummethod and stratumtype tables.

Important: *All* length- or area-related measurements throughout VegBIEN must be converted to SI base units, e.g. cm -> m, ha -> m^2.**';


--
-- Name: COLUMN method.source_id; Type: COMMENT; Schema: public; Owner: -
--

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.';


--
-- Name: COLUMN method.name; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.name IS 'A short name for the set of methods used. Although there is no existing standard, many names are widely used, and could be useful for finding plots with similar methodology.';


--
-- Name: COLUMN method.description; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.description IS 'Additional metadata helpful for understanding how the data were collected during the observation event.';


--
-- Name: COLUMN method.diameterheight_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.diameterheight_m IS 'The height in m at which the diameter is measured. e.g. 1.37 m for breast height (DBH).';


--
-- Name: COLUMN method.mindiameter_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.mindiameter_m IS 'Lower diameter limit in m for inclusion of a tree.';


--
-- Name: COLUMN method.maxdiameter_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.maxdiameter_m IS 'Upper diameter limit in m for inclusion of a tree.';


--
-- Name: COLUMN method.minheight_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.minheight_m IS 'Lower height limit in m for inclusion of a tree.';


--
-- Name: COLUMN method.maxheight_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.maxheight_m IS 'Upper height limit in m for inclusion of a tree.';


--
-- Name: COLUMN method.observationtype; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.observationtype IS 'values: aggregate, individual, both';


--
-- Name: COLUMN method.observationmeasure; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.observationmeasure IS 'e.g. count, cover, presence, points-intercepted, distance-intercepted';


--
-- Name: COLUMN method.samplingfactor; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.samplingfactor IS 'Here, we could explicitly say that we are sampling a particular area by a different size representative sample area. Simply divide the number of plants connected to this record by this value to get the extrapolated (or interpolated) number of plants in the area in question. This explicitly notes a subsample or supersample.';


--
-- Name: COLUMN method.coverbasis; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.coverbasis IS 'Were cover values for the total taxon list collected from one contiguous area or dispersed subplots?

entire: Cover based on observation of an entire plot consisting of a single contiguous area of land. subplot-contiguous: Cover based on observation of a single contiguous area of land of less spatial extent than the entire plot.

subplot-regular: Cover based on observation of multiple subplots arranged in a regular pattern within the overall plot.

subplot-random: Cover based on observation of multiple randomly dispersed subplots within the overall plot.

subplot-haphazard: Cover based on observation of multiple subplots haphazardly arranged within the overall plot.

line-intercept: Cover based on length of line touching each species present.

point-intercept: Cover based on number of points for each species present.
';


--
-- Name: COLUMN method.stemsamplemethod; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.stemsamplemethod IS 'The method used to obtain basal area or tree stem data (e.g., full census, point quarter, random pairs, Bitterlich, other).

e.g.:
Full census
Point quarter
Random pairs
Bitterlich
Other
Subsample census';


--
-- Name: COLUMN method.shape; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.shape IS 'e.g. square, rectangle, circle, line, point, other';


--
-- Name: COLUMN method.samplearea_m2; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.samplearea_m2 IS 'The total surface area used for cover estimates and for which a complete species list is provided. If subplots were used, this would be the total area of the subplots without interstitial space.';


--
-- Name: COLUMN method.subplotspacing_m; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.subplotspacing_m IS 'Spacing in m between adjacent subplots, lines (line-intercept data), or points (point-intercept data).';


--
-- Name: COLUMN method.subplotmethod_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.subplotmethod_id IS 'Method to use for each subplot/line/point, which will specify subplot size, line length, etc.';


--
-- Name: COLUMN method.pointsperline; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN method.pointsperline IS 'The number of points sampled on each line subplot for point-intercept data.';


--
-- Name: party; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE party (
    party_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    fullname text,
    salutation text,
    givenname text,
    middlename text,
    surname text,
    suffix text,
    department text,
    organizationname text,
    currentname_id integer,
    contactinstructions text,
    email text,
    partytype text,
    partypublic boolean DEFAULT true,
    CONSTRAINT party_required_key CHECK (((organizationname IS NOT NULL) OR ((source_id <> party_id) AND ((fullname IS NOT NULL) OR (surname IS NOT NULL)))))
);


--
-- Name: plantobservation; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE plantobservation (
    plantobservation_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    aggregateoccurrence_id integer,
    overallheight_m double precision,
    overallheightaccuracy_m double precision,
    authorplantcode text,
    stemcount integer,
    reproductivecondition text,
    plant_id integer,
    CONSTRAINT plantobservation_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (aggregateoccurrence_id IS NOT NULL)))
);


--
-- Name: TABLE plantobservation; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE plantobservation IS 'Equivalent to VegBank''s stemcount table.';


--
-- Name: COLUMN plantobservation.authorplantcode; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN plantobservation.authorplantcode IS 'The number of the organism within the data collection or event.';


--
-- Name: project; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE project (
    project_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    projectname text,
    projectdescription text,
    startdate date,
    stopdate date,
    CONSTRAINT project_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (projectname IS NOT NULL)))
);


--
-- Name: sourcelist; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE sourcelist (
    sourcelist_id integer NOT NULL,
    source_id integer NOT NULL,
    name text NOT NULL
);


--
-- Name: specimenreplicate; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE specimenreplicate (
    specimenreplicate_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    plantobservation_id integer,
    institution_id integer,
    collectioncode_dwc text,
    catalognumber_dwc text,
    collectionnumber text,
    description text,
    specimen_id integer,
    CONSTRAINT specimenreplicate_required_key CHECK ((((plantobservation_id IS NOT NULL) OR (sourceaccessioncode IS NOT NULL)) OR (catalognumber_dwc IS NOT NULL)))
);


--
-- Name: TABLE specimenreplicate; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE specimenreplicate IS 'A herbarium''s replicate of a specimen. Contains Darwin Core specimen data.';


--
-- Name: COLUMN specimenreplicate.institution_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN specimenreplicate.institution_id IS 'The institution (such as a museum) that the specimenreplicate is from.';


--
-- Name: COLUMN specimenreplicate.collectioncode_dwc; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN specimenreplicate.collectioncode_dwc IS 'The code for the collection that the specimenreplicate is from.';


--
-- Name: stemobservation; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE stemobservation (
    stemobservation_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    plantobservation_id integer NOT NULL,
    authorstemcode text,
    tag text,
    tags text,
    xposition_m double precision,
    yposition_m double precision,
    diameterbreastheight_m double precision,
    basaldiameter_m double precision,
    diameteraccuracy_m double precision,
    height_m double precision,
    heightfirstbranch_m double precision,
    heightaccuracy_m double precision,
    health text,
    age double precision,
    CONSTRAINT stemobservation_non_empty CHECK (((((((((sourceaccessioncode IS NOT NULL) OR (authorstemcode IS NOT NULL)) OR (tag IS NOT NULL)) OR (xposition_m IS NOT NULL)) OR (diameterbreastheight_m IS NOT NULL)) OR (basaldiameter_m IS NOT NULL)) OR (height_m IS NOT NULL)) OR (heightfirstbranch_m IS NOT NULL)))
);


--
-- Name: TABLE stemobservation; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE stemobservation IS 'Equivalent to VegBank''s stemlocation table.';


--
-- Name: COLUMN stemobservation.tags; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN stemobservation.tags IS 'Stores all tags when multiple tags provided. Older tags go first.';


--
-- Name: stratum; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE stratum (
    stratum_id integer NOT NULL,
    source_id integer NOT NULL,
    stratumname text NOT NULL,
    stratumheight double precision,
    stratumbase double precision,
    stratumcover double precision,
    area double precision,
    method_id integer
);


--
-- Name: taxondetermination; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxondetermination (
    taxondetermination_id integer NOT NULL,
    taxonoccurrence_id integer NOT NULL,
    source_id integer NOT NULL,
    taxonverbatim_id integer NOT NULL,
    party_id integer,
    role role DEFAULT 'unknown'::role NOT NULL,
    determinationtype text,
    reference_id integer,
    isoriginal boolean DEFAULT false NOT NULL,
    is_datasource_current boolean DEFAULT false NOT NULL,
    iscurrent boolean DEFAULT false NOT NULL,
    taxonfit text,
    taxonconfidence text,
    grouptype text,
    notes text,
    revisions boolean,
    determinationdate date
);


--
-- Name: TABLE taxondetermination; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE taxondetermination IS 'Equivalent to VegBank''s taxoninterpretation table.';


--
-- Name: taxonoccurrence; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonoccurrence (
    taxonoccurrence_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceaccessioncode text,
    locationevent_id integer,
    authortaxoncode text,
    collector_id integer,
    growthform growthform,
    iscultivated boolean,
    cultivatedbasis text,
    isnative boolean,
    CONSTRAINT taxonoccurrence_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (locationevent_id IS NOT NULL)))
);


--
-- Name: TABLE taxonoccurrence; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE taxonoccurrence IS 'Equivalent to VegBank''s taxonobservation table.';


--
-- Name: COLUMN taxonoccurrence.iscultivated; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonoccurrence.iscultivated IS 'cultivated or wild';


--
-- Name: COLUMN taxonoccurrence.cultivatedbasis; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonoccurrence.cultivatedbasis IS 'The reason why a taxonoccurrence was marked as cultivated (or not).';


--
-- Name: COLUMN taxonoccurrence.isnative; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonoccurrence.isnative IS 'native or exotic';


--
-- Name: taxonverbatim; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonverbatim (
    taxonverbatim_id integer NOT NULL,
    source_id integer NOT NULL,
    taxonlabel_id integer,
    verbatimrank text,
    taxonomicname text,
    taxonname text,
    author text,
    family text,
    genus text,
    specific_epithet text,
    morphospecies text,
    morphoname text,
    growthform growthform,
    description text,
    CONSTRAINT taxonverbatim_required_key CHECK (((taxonlabel_id IS NOT NULL) OR (morphoname IS NOT NULL)))
);


--
-- Name: TABLE taxonverbatim; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE taxonverbatim IS 'Component parts of the taxonlabel. Contains the datasource''s original taxonomic name components, as well as any parsed components produced by name resolution.';


--
-- Name: COLUMN taxonverbatim.verbatimrank; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.verbatimrank IS 'The taxon''s verbatim level in the taxonomic hierarchy. Does not need to be in the taxonrank closed list.';


--
-- Name: COLUMN taxonverbatim.taxonomicname; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.taxonomicname IS 'The full taxonomic name which uniquely identifies this taxon, including the author of that name. The family should be omitted if possible.

Equivalent to Darwin Core''s scientificName.';


--
-- Name: COLUMN taxonverbatim.taxonname; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.taxonname IS 'The taxonomic name without the author. The family should be omitted if possible.';


--
-- Name: COLUMN taxonverbatim.author; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.author IS 'The author of the taxonomic name.

Equivalent to Darwin Core''s scientificNameAuthorship.';


--
-- Name: COLUMN taxonverbatim.family; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.family IS 'The family of the taxonomic name. This is a cached field for easy querying; this should also be stored in taxonlabel at the appropriate rank.';


--
-- Name: COLUMN taxonverbatim.genus; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.genus IS 'The genus portion of the taxonomic name. This is a cached field for easy querying; this should also be stored in taxonlabel at the appropriate rank.';


--
-- Name: COLUMN taxonverbatim.specific_epithet; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.specific_epithet IS 'The specific epithet portion of the taxonomic name. This is a cached field for easy querying; this should also be stored in taxonlabel at the appropriate rank.';


--
-- Name: COLUMN taxonverbatim.morphospecies; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonverbatim.morphospecies IS 'The morphospecies suffix.';


--
-- Name: threatened_taxonlabel; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE threatened_taxonlabel (
    taxonlabel_id integer NOT NULL
);


--
-- Name: analytical_stem_view; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW analytical_stem_view AS
    SELECT source.shortname AS datasource, sourcelist.name AS "institutionCode", specimenreplicate.collectioncode_dwc AS "collectionCode", specimenreplicate.catalognumber_dwc AS "catalogNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", COALESCE(geoscrub_output."acceptedCountry", place.country) AS country, COALESCE(geoscrub_output."acceptedStateProvince", place.stateprovince) AS "stateProvince", COALESCE(geoscrub_output."acceptedCounty", place.county) AS county, location.locationnarrative AS locality, CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN coordinates.latitude_deg ELSE county_centroids.latitude END AS "decimalLatitude", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN coordinates.longitude_deg ELSE county_centroids.longitude END AS "decimalLongitude", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN coordinates.coordsaccuracy_m ELSE _km_to_m(county_centroids.error_km) END AS "coordinateUncertaintyInMeters", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN 'source data'::coordinatesource WHEN (county_centroids.row_num IS NOT NULL) THEN 'georeferencing'::coordinatesource ELSE NULL::coordinatesource END AS "coordinateSource_bien", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN NULL::text WHEN (county_centroids.row_num IS NOT NULL) THEN 'county centroid'::text ELSE NULL::text END AS "georeferenceProtocol_bien", (geoscrub_output.geovalid)::integer AS geovalid_bien, ("newWorldCountries"."isNewWorld")::integer AS "isNewWorld_bien", COALESCE(project.sourceaccessioncode, project.projectname) AS "projectID", COALESCE(location.sourceaccessioncode, NULLIF(pg_catalog.concat_ws('; '::text, COALESCE(parent_location.sourceaccessioncode, parent_location.authorlocationcode), location.authorlocationcode), ''::text)) AS "locationID", COALESCE(parent_location.authorlocationcode, location.authorlocationcode) AS "locationName", CASE WHEN (parent_location.location_id IS NOT NULL) THEN location.authorlocationcode ELSE NULL::text END AS subplot, plantobservation.authorplantcode AS "individualCode", COALESCE(location.elevation_m, parent_location.elevation_m) AS "elevationInMeters", _m2_to_ha(COALESCE(location.area_m2, parent_location.area_m2)) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.temperature_c, parent_event.temperature_c) AS "temperature_C", COALESCE(locationevent.precipitation_m, parent_event.precipitation_m) AS precipitation_m, stratum.stratumname AS stratum__name, COALESCE(locationevent__communities__array(locationevent.locationevent_id), locationevent__communities__array(parent_event.locationevent_id)) AS communities, COALESCE(locationevent__contributors__array(locationevent.locationevent_id), locationevent__contributors__array(parent_event.locationevent_id)) AS plot__collectors, collector.fullname AS "recordedBy", plantobservation.authorplantcode AS "recordNumber", COALESCE(locationevent.obsstartdate, parent_event.obsstartdate, aggregateoccurrence.collectiondate) AS "dateCollected", taxonverbatim.family AS family_verbatim, COALESCE(taxonverbatim.taxonomicname, NULLIF(pg_catalog.concat_ws(' '::text, taxonverbatim.taxonname, taxonverbatim.author), ''::text), taxonlabel.taxonomicname) AS "scientificName_verbatim", identifiedby.fullname AS "identifiedBy", taxondetermination.determinationdate AS "dateIdentified", taxondetermination.notes AS "identificationRemarks", "ScrubbedTaxon"."matchedFamily" AS family_matched, "ScrubbedTaxon"."matchedTaxonName" AS "taxonName_matched", "ScrubbedTaxon"."matchedScientificNameAuthorship" AS "scientificNameAuthorship_matched", family_higher_plant_group.higher_plant_group AS "higherPlantGroup_bien", "ScrubbedTaxon"."acceptedFamily" AS family, "ScrubbedTaxon"."acceptedGenus" AS genus, COALESCE(COALESCE(NULLIF(pg_catalog.concat_ws(' '::text, COALESCE("ScrubbedTaxon"."acceptedGenus", "ScrubbedTaxon"."acceptedFamily"), "ScrubbedTaxon"."acceptedSpecificEpithet", "ScrubbedTaxon"."morphospeciesSuffix"), ''::text), "ScrubbedTaxon"."acceptedTaxonName"), COALESCE(NULLIF(pg_catalog.concat_ws(' '::text, COALESCE("ScrubbedTaxon"."matchedGenus", "ScrubbedTaxon"."matchedFamily"), "ScrubbedTaxon"."matchedSpecificEpithet", "ScrubbedTaxon"."morphospeciesSuffix"), ''::text), "ScrubbedTaxon"."matchedTaxonName"), "ScrubbedTaxon"."concatenatedScientificName") AS "speciesBinomialWithMorphospecies", "ScrubbedTaxon"."acceptedTaxonName" AS "taxonName", "ScrubbedTaxon"."acceptedScientificNameAuthorship" AS "scientificNameAuthorship", taxonoccurrence.growthform AS "growthForm", plantobservation.reproductivecondition AS "reproductiveCondition", ((threatened_taxonlabel.taxonlabel_id IS NOT NULL))::integer AS threatened_bien, (((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, location.iscultivated)))::integer AS cultivated_bien, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis_bien", aggregateoccurrence.notes AS "occurrenceRemarks", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "coverPercent", _m_to_cm(stemobservation.diameterbreastheight_m) AS "diameterBreastHeight_cm", stemobservation.height_m, stemobservation.tag, stemobservation.xposition_m AS "organismX_m", stemobservation.yposition_m AS "organismY_m", taxonoccurrence.sourceaccessioncode AS "taxonOccurrenceID", taxonoccurrence.authortaxoncode AS "authorTaxonCode", aggregateoccurrence.sourceaccessioncode AS "aggregateOrganismObservationID", plantobservation.sourceaccessioncode AS "individualObservationID", stemobservation.authorstemcode AS "authorStemCode" FROM (((((((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationevent USING (location_id)) LEFT JOIN location parent_location ON ((parent_location.location_id = location.parent_id))) LEFT JOIN locationplace ON ((locationplace.location_id = COALESCE(parent_location.location_id, location.location_id)))) LEFT JOIN place USING (place_id)) LEFT JOIN coordinates USING (coordinates_id)) LEFT JOIN geoscrub.geoscrub_output ON ((((((ARRAY[geoscrub_output."decimalLatitude"] = ARRAY[coordinates.latitude_deg]) AND (ARRAY[geoscrub_output."decimalLongitude"] = ARRAY[coordinates.longitude_deg])) AND (ARRAY[geoscrub_output.country] = ARRAY[place.country])) AND (ARRAY[geoscrub_output."stateProvince"] = ARRAY[place.stateprovince])) AND (ARRAY[geoscrub_output.county] = ARRAY[place.county])))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."*GADM country" = COALESCE(geoscrub_output."acceptedCountry", place.country)))) LEFT JOIN "newWorld"."newWorldCountries" ON (("newWorldCountries"."*isoCode" = iso_code_gadm."*2-digit iso code"))) LEFT JOIN geoscrub.county_centroids ON ((((place.country = 'United States'::text) AND (county_centroids.state = COALESCE(geoscrub_output."acceptedStateProvince", place.stateprovince))) AND (county_centroids.county = COALESCE(geoscrub_output."acceptedCounty", place.county))))) LEFT JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN locationevent parent_event ON ((parent_event.locationevent_id = locationevent.parent_id))) LEFT JOIN project ON ((project.project_id = COALESCE(locationevent.project_id, parent_event.project_id)))) LEFT JOIN stratum ON ((stratum.stratum_id = COALESCE(locationevent.stratum_id, parent_event.stratum_id)))) LEFT JOIN method ON ((method.method_id = COALESCE(locationevent.method_id, parent_event.method_id)))) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcelist ON ((sourcelist.sourcelist_id = specimenreplicate.institution_id))) LEFT JOIN taxondetermination ON (((taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id) AND taxondetermination.is_datasource_current))) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel USING (taxonlabel_id)) LEFT JOIN "TNRS"."ScrubbedTaxon" ON (("ScrubbedTaxon"."concatenatedScientificName" = taxonlabel.taxonomicname))) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = "ScrubbedTaxon"."acceptedFamily"))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = "ScrubbedTaxon"."acceptedFamily") AND (cultivated_family_locations.country = COALESCE(geoscrub_output."acceptedCountry", place.country))))) LEFT JOIN threatened_taxonlabel USING (taxonlabel_id)) ORDER BY source.shortname;


--
-- Name: VIEW analytical_stem_view; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON VIEW analytical_stem_view IS 'after updating this:
SELECT sync_analytical_stem_to_view()
add applicable columns to analytical_specimen, analytical_plot';


--
-- Name: classcontributor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE classcontributor (
    classcontributor_id integer NOT NULL,
    commclass_id integer NOT NULL,
    party_id integer NOT NULL,
    role role
);


--
-- Name: classcontributor_classcontributor_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE classcontributor_classcontributor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: classcontributor_classcontributor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE classcontributor_classcontributor_id_seq OWNED BY classcontributor.classcontributor_id;


--
-- Name: classcontributor_classcontributor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commclass; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commclass (
    commclass_id integer NOT NULL,
    locationevent_id integer NOT NULL,
    inspection boolean,
    tableanalysis boolean,
    multivariateanalysis boolean,
    classpublication_id integer,
    classnotes text,
    commname text,
    commcode text,
    commframework text,
    commlevel text,
    classstartdate date,
    classstopdate date,
    expertsystem text
);


--
-- Name: commclass_commclass_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commclass_commclass_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commclass_commclass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commclass_commclass_id_seq OWNED BY commclass.commclass_id;


--
-- Name: commclass_commclass_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commconcept; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commconcept (
    commconcept_id integer NOT NULL,
    commname_id integer NOT NULL,
    reference_id integer,
    commdescription text,
    commname text
);


--
-- Name: commconcept_commconcept_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commconcept_commconcept_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commconcept_commconcept_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commconcept_commconcept_id_seq OWNED BY commconcept.commconcept_id;


--
-- Name: commconcept_commconcept_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commcorrelation; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commcorrelation (
    commcorrelation_id integer NOT NULL,
    commstatus_id integer NOT NULL,
    commconcept_id integer NOT NULL,
    commconvergence text NOT NULL,
    correlationstart date NOT NULL,
    correlationstop date
);


--
-- Name: commcorrelation_commcorrelation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commcorrelation_commcorrelation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commcorrelation_commcorrelation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commcorrelation_commcorrelation_id_seq OWNED BY commcorrelation.commcorrelation_id;


--
-- Name: commcorrelation_commcorrelation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commdetermination; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commdetermination (
    commdetermination_id integer NOT NULL,
    commclass_id integer NOT NULL,
    commconcept_id integer NOT NULL,
    commcode text,
    commname text,
    classfit text,
    classconfidence text,
    commauthority_id integer,
    notes text,
    type boolean,
    nomenclaturaltype boolean
);


--
-- Name: commdetermination_commdetermination_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commdetermination_commdetermination_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commdetermination_commdetermination_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commdetermination_commdetermination_id_seq OWNED BY commdetermination.commdetermination_id;


--
-- Name: commdetermination_commdetermination_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commlineage; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commlineage (
    commlineage_id integer NOT NULL,
    parentcommstatus_id integer NOT NULL,
    childcommstatus_id integer NOT NULL
);


--
-- Name: commlineage_commlineage_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commlineage_commlineage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commlineage_commlineage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commlineage_commlineage_id_seq OWNED BY commlineage.commlineage_id;


--
-- Name: commlineage_commlineage_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commname; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commname (
    commname_id integer NOT NULL,
    commname text NOT NULL,
    source_id integer,
    dateentered date DEFAULT now()
);


--
-- Name: commname_commname_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commname_commname_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commname_commname_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commname_commname_id_seq OWNED BY commname.commname_id;


--
-- Name: commname_commname_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commstatus; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commstatus (
    commstatus_id integer NOT NULL,
    commconcept_id integer NOT NULL,
    source_id integer,
    commconceptstatus text NOT NULL,
    commparent_id integer,
    commlevel text,
    commpartycomments text,
    party_id integer NOT NULL,
    startdate date NOT NULL,
    stopdate date
);


--
-- Name: commstatus_commstatus_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commstatus_commstatus_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commstatus_commstatus_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commstatus_commstatus_id_seq OWNED BY commstatus.commstatus_id;


--
-- Name: commstatus_commstatus_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: commusage; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE commusage (
    commusage_id integer NOT NULL,
    commname_id integer NOT NULL,
    commname text,
    commconcept_id integer,
    commnamestatus text,
    classsystem text,
    party_id integer,
    commstatus_id integer,
    usagestart date,
    usagestop date
);


--
-- Name: commusage_commusage_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE commusage_commusage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: commusage_commusage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE commusage_commusage_id_seq OWNED BY commusage.commusage_id;


--
-- Name: commusage_commusage_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: coordinates_coordinates_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE coordinates_coordinates_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: coordinates_coordinates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE coordinates_coordinates_id_seq OWNED BY coordinates.coordinates_id;


--
-- Name: coordinates_coordinates_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: coverindex; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE coverindex (
    coverindex_id integer NOT NULL,
    covermethod_id integer NOT NULL,
    covercode text NOT NULL,
    upperlimit double precision,
    lowerlimit double precision,
    coverpercent double precision NOT NULL,
    indexdescription text
);


--
-- Name: coverindex_coverindex_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE coverindex_coverindex_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: coverindex_coverindex_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE coverindex_coverindex_id_seq OWNED BY coverindex.coverindex_id;


--
-- Name: coverindex_coverindex_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: covermethod; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE covermethod (
    covermethod_id integer NOT NULL,
    source_id integer,
    covertype text NOT NULL,
    coverestimationmethod text
);


--
-- Name: covermethod_covermethod_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE covermethod_covermethod_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: covermethod_covermethod_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE covermethod_covermethod_id_seq OWNED BY covermethod.covermethod_id;


--
-- Name: covermethod_covermethod_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: dba_preassignacccode_dba_requestnumber_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE dba_preassignacccode_dba_requestnumber_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: dba_preassignacccode_dba_requestnumber_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: definedvalue; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE definedvalue (
    definedvalue_id integer NOT NULL,
    userdefined_id integer NOT NULL,
    tablerecord_id integer NOT NULL,
    definedvalue text
);


--
-- Name: definedvalue_definedvalue_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE definedvalue_definedvalue_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: definedvalue_definedvalue_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE definedvalue_definedvalue_id_seq OWNED BY definedvalue.definedvalue_id;


--
-- Name: definedvalue_definedvalue_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: disturbanceobs; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE disturbanceobs (
    disturbanceobs_id integer NOT NULL,
    locationevent_id integer NOT NULL,
    disturbancetype text NOT NULL,
    disturbanceintensity text,
    disturbanceage double precision,
    disturbanceextent double precision,
    disturbancecomment text
);


--
-- Name: disturbanceobs_disturbanceobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE disturbanceobs_disturbanceobs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: disturbanceobs_disturbanceobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE disturbanceobs_disturbanceobs_id_seq OWNED BY disturbanceobs.disturbanceobs_id;


--
-- Name: disturbanceobs_disturbanceobs_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: geoscrub_input; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE geoscrub_input (
    country text,
    "stateProvince" text,
    county text,
    "decimalLatitude" double precision,
    "decimalLongitude" double precision
);


--
-- Name: geoscrub_input_new; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW geoscrub_input_new AS
    SELECT geoscrub_input.country, geoscrub_input."stateProvince", geoscrub_input.county, geoscrub_input."decimalLatitude", geoscrub_input."decimalLongitude" FROM (geoscrub_input LEFT JOIN geoscrub.geoscrub_output ON ((((((geoscrub_output."decimalLatitude" = geoscrub_input."decimalLatitude") AND (geoscrub_output."decimalLongitude" = geoscrub_input."decimalLongitude")) AND (geoscrub_output.country = geoscrub_input.country)) AND (geoscrub_output."stateProvince" = geoscrub_input."stateProvince")) AND (geoscrub_output.county = geoscrub_input.county)))) WHERE (geoscrub_output."*row_num" IS NULL);


--
-- Name: geoscrub_input_view; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW geoscrub_input_view AS
    SELECT DISTINCT place.country, place.stateprovince AS "stateProvince", place.county, coordinates.latitude_deg AS "decimalLatitude", coordinates.longitude_deg AS "decimalLongitude" FROM (place JOIN coordinates USING (coordinates_id)) WHERE (place.country IS NOT NULL);


--
-- Name: graphic; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE graphic (
    graphic_id integer NOT NULL,
    locationevent_id integer NOT NULL,
    graphicname text,
    graphiclocation text,
    graphicdescription text,
    graphictype text,
    graphicdata oid,
    graphicdate date
);


--
-- Name: graphic_graphic_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE graphic_graphic_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: graphic_graphic_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE graphic_graphic_id_seq OWNED BY graphic.graphic_id;


--
-- Name: graphic_graphic_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: higher_plant_group_nodes; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE higher_plant_group_nodes (
    higher_plant_group higher_plant_group,
    node_name text NOT NULL
);


--
-- Name: location_location_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE location_location_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: location_location_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE location_location_id_seq OWNED BY location.location_id;


--
-- Name: location_location_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: locationevent_locationevent_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE locationevent_locationevent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: locationevent_locationevent_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE locationevent_locationevent_id_seq OWNED BY locationevent.locationevent_id;


--
-- Name: locationevent_locationevent_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: locationeventcontributor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE locationeventcontributor (
    locationeventcontributor_id integer NOT NULL,
    locationevent_id integer NOT NULL,
    party_id integer NOT NULL,
    role role,
    contributiondate date
);


--
-- Name: locationeventcontributor_locationeventcontributor_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE locationeventcontributor_locationeventcontributor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: locationeventcontributor_locationeventcontributor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE locationeventcontributor_locationeventcontributor_id_seq OWNED BY locationeventcontributor.locationeventcontributor_id;


--
-- Name: locationeventcontributor_locationeventcontributor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: locationeventsynonym; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE locationeventsynonym (
    locationeventsynonym_id integer NOT NULL,
    synonymlocationevent_id integer NOT NULL,
    primarylocationevent_id integer NOT NULL,
    party_id integer NOT NULL,
    role role NOT NULL,
    synonymcomment text,
    classstartdate date DEFAULT now() NOT NULL,
    classstopdate date
);


--
-- Name: locationeventsynonym_locationeventsynonym_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE locationeventsynonym_locationeventsynonym_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: locationeventsynonym_locationeventsynonym_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE locationeventsynonym_locationeventsynonym_id_seq OWNED BY locationeventsynonym.locationeventsynonym_id;


--
-- Name: locationeventsynonym_locationeventsynonym_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: locationplace_locationplace_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE locationplace_locationplace_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: locationplace_locationplace_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE locationplace_locationplace_id_seq OWNED BY locationplace.locationplace_id;


--
-- Name: locationplace_locationplace_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: method_method_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE method_method_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: method_method_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE method_method_id_seq OWNED BY method.method_id;


--
-- Name: method_method_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: methodtaxonclass; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE methodtaxonclass (
    methodtaxonclass_id integer NOT NULL,
    method_id integer NOT NULL,
    taxonlabel_id integer,
    included boolean NOT NULL,
    submethod_id integer,
    taxonclass taxonclass,
    CONSTRAINT methodtaxonclass_key_required CHECK (((taxonlabel_id IS NOT NULL) OR (taxonclass IS NOT NULL)))
);


--
-- Name: COLUMN methodtaxonclass.included; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN methodtaxonclass.included IS 'Whether the method includes or excludes this taxon class.';


--
-- Name: COLUMN methodtaxonclass.submethod_id; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN methodtaxonclass.submethod_id IS 'The submethod used to sample just this taxon class, distinct from the main method.';


--
-- Name: methodtaxonclass_methodtaxonclass_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE methodtaxonclass_methodtaxonclass_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: methodtaxonclass_methodtaxonclass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE methodtaxonclass_methodtaxonclass_id_seq OWNED BY methodtaxonclass.methodtaxonclass_id;


--
-- Name: methodtaxonclass_methodtaxonclass_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: note; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE note (
    note_id integer NOT NULL,
    notelink_id integer NOT NULL,
    party_id integer NOT NULL,
    role role NOT NULL,
    notetype text NOT NULL,
    notetext text NOT NULL,
    notedate date
);


--
-- Name: note_note_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE note_note_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: note_note_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE note_note_id_seq OWNED BY note.note_id;


--
-- Name: note_note_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: notelink; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE notelink (
    notelink_id integer NOT NULL,
    tablename text NOT NULL,
    attributename text,
    tablerecord integer NOT NULL
);


--
-- Name: notelink_notelink_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE notelink_notelink_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: notelink_notelink_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE notelink_notelink_id_seq OWNED BY notelink.notelink_id;


--
-- Name: notelink_notelink_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: party_party_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE party_party_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: party_party_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE party_party_id_seq OWNED BY party.party_id;


--
-- Name: party_party_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: partymember; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE partymember (
    partymember_id integer NOT NULL,
    parentparty_id integer NOT NULL,
    childparty_id integer NOT NULL,
    role role,
    memberstart date DEFAULT now() NOT NULL,
    memberstop date
);


--
-- Name: partymember_partymember_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE partymember_partymember_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: partymember_partymember_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE partymember_partymember_id_seq OWNED BY partymember.partymember_id;


--
-- Name: partymember_partymember_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: place_place_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE place_place_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: place_place_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE place_place_id_seq OWNED BY place.place_id;


--
-- Name: place_place_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: placecorrelation; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE placecorrelation (
    placecorrelation_id integer NOT NULL,
    parentplace_id integer NOT NULL,
    childplace_id integer NOT NULL,
    placeconvergence text NOT NULL
);


--
-- Name: placecorrelation_placecorrelation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE placecorrelation_placecorrelation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: placecorrelation_placecorrelation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE placecorrelation_placecorrelation_id_seq OWNED BY placecorrelation.placecorrelation_id;


--
-- Name: placecorrelation_placecorrelation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: placename; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE placename (
    placename_id integer NOT NULL,
    parent_id integer,
    rank placerank NOT NULL,
    placename text NOT NULL
);


--
-- Name: TABLE placename; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE placename IS 'An official, named placename. Can be at any level in the geographic hierarchy. Note that the placename stores only one rank (e.g. country) of the full path to the placename. The higher-level ranks are stored in the placename''s chain of parent_id ancestors.

Equivalent to VegBank''s namedPlace table.';


--
-- Name: placename_ancestor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE placename_ancestor (
    placename_id integer NOT NULL,
    ancestor_id integer NOT NULL
);


--
-- Name: TABLE placename_ancestor; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE placename_ancestor IS 'placename''s ancestor cross link table.';


--
-- Name: placename_placename_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE placename_placename_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: placename_placename_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE placename_placename_id_seq OWNED BY placename.placename_id;


--
-- Name: placename_placename_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: plant; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE plant (
    plant_id integer NOT NULL
);


--
-- Name: TABLE plant; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE plant IS 'A physical, tagged plant.';


--
-- Name: plant_plant_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE plant_plant_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: plant_plant_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE plant_plant_id_seq OWNED BY plant.plant_id;


--
-- Name: plant_plant_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: plantobservation_plantobservation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE plantobservation_plantobservation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: plantobservation_plantobservation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE plantobservation_plantobservation_id_seq OWNED BY plantobservation.plantobservation_id;


--
-- Name: plantobservation_plantobservation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: plot.**; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW "plot.**" AS
    SELECT source.shortname AS datasource, canon_place.country, canon_place.stateprovince AS "stateProvince", datasource_place.county, location.locationnarrative AS locality, CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN coordinates.latitude_deg ELSE county_centroids.latitude END AS "decimalLatitude", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN coordinates.longitude_deg ELSE county_centroids.longitude END AS "decimalLongitude", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN coordinates.coordsaccuracy_m ELSE _km_to_m(county_centroids.error_km) END AS "coordinateUncertaintyInMeters", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN 'source data'::coordinatesource WHEN (county_centroids.row_num IS NOT NULL) THEN 'georeferencing'::coordinatesource ELSE NULL::coordinatesource END AS "coordinateSource_bien", CASE WHEN (coordinates.latitude_deg IS NOT NULL) THEN NULL::text WHEN (county_centroids.row_num IS NOT NULL) THEN 'county centroid'::text ELSE NULL::text END AS "georeferenceProtocol_bien", (canon_place.geovalid)::integer AS geovalid_bien, ("newWorldCountries"."isNewWorld")::integer AS "isNewWorld_bien", COALESCE(project.sourceaccessioncode, project.projectname) AS "projectID", COALESCE(location.sourceaccessioncode, NULLIF(pg_catalog.concat_ws('; '::text, COALESCE(parent_location.sourceaccessioncode, parent_location.authorlocationcode), location.authorlocationcode), ''::text)) AS "locationID", COALESCE(parent_location.authorlocationcode, location.authorlocationcode) AS "locationName", CASE WHEN (parent_location.location_id IS NOT NULL) THEN location.authorlocationcode ELSE NULL::text END AS subplot, COALESCE(location.elevation_m, parent_location.elevation_m) AS "elevationInMeters", _m2_to_ha(COALESCE(location.area_m2, parent_location.area_m2)) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.temperature_c, parent_event.temperature_c) AS "temperature_C", COALESCE(locationevent.precipitation_m, parent_event.precipitation_m) AS precipitation_m, stratum.stratumname AS stratum__name, COALESCE(locationevent__communities__array(locationevent.locationevent_id), locationevent__communities__array(parent_event.locationevent_id)) AS communities, COALESCE(locationevent__contributors__array(locationevent.locationevent_id), locationevent__contributors__array(parent_event.locationevent_id)) AS plot__collectors FROM ((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationevent USING (location_id)) LEFT JOIN location parent_location ON ((parent_location.location_id = location.parent_id))) LEFT JOIN locationplace ON ((locationplace.location_id = COALESCE(parent_location.location_id, location.location_id)))) LEFT JOIN place datasource_place USING (place_id)) LEFT JOIN place canon_place ON ((canon_place.place_id = datasource_place.canon_place_id))) LEFT JOIN coordinates ON ((coordinates.coordinates_id = canon_place.coordinates_id))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."*GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON (("newWorldCountries"."*isoCode" = iso_code_gadm."*2-digit iso code"))) LEFT JOIN geoscrub.county_centroids ON ((((canon_place.country = 'United States'::text) AND (county_centroids.state = canon_place.stateprovince)) AND (county_centroids.county = canon_place.county)))) LEFT JOIN locationevent parent_event ON ((parent_event.locationevent_id = locationevent.parent_id))) LEFT JOIN project ON ((project.project_id = COALESCE(locationevent.project_id, parent_event.project_id)))) LEFT JOIN stratum ON ((stratum.stratum_id = COALESCE(locationevent.stratum_id, parent_event.stratum_id)))) LEFT JOIN method ON ((method.method_id = COALESCE(locationevent.method_id, parent_event.method_id))));


--
-- Name: project_project_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE project_project_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: project_project_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE project_project_id_seq OWNED BY project.project_id;


--
-- Name: project_project_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: projectcontributor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE projectcontributor (
    projectcontributor_id integer NOT NULL,
    project_id integer NOT NULL,
    party_id integer NOT NULL,
    role role
);


--
-- Name: projectcontributor_projectcontributor_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE projectcontributor_projectcontributor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: projectcontributor_projectcontributor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE projectcontributor_projectcontributor_id_seq OWNED BY projectcontributor.projectcontributor_id;


--
-- Name: projectcontributor_projectcontributor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: provider_count; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE provider_count (
    dataprovider text NOT NULL,
    dataset text NOT NULL,
    records bigint,
    sourcetype sourcetype,
    observationtype observationtype
);


--
-- Name: sourcename; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE sourcename (
    sourcelist_id integer NOT NULL,
    name text NOT NULL,
    matched_source_id integer
);


--
-- Name: provider_count_view; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW provider_count_view AS
    (SELECT s.dataprovider, '(total)'::text AS dataset, s.records, source.sourcetype, source.observationtype FROM ((SELECT analytical_stem.datasource AS dataprovider, count(*) AS records FROM analytical_stem GROUP BY analytical_stem.datasource) s JOIN source ON ((source.shortname = s.dataprovider))) ORDER BY s.records DESC) UNION ALL (SELECT dataprovider.shortname AS dataprovider, s.dataset, s.records, dataset.sourcetype, COALESCE(dataset.observationtype, dataprovider.observationtype) AS observationtype FROM (((SELECT specimenreplicate.source_id AS dataprovider_id, sourcename.name AS dataset, sourcename.matched_source_id AS dataset_id, count(*) AS records FROM ((specimenreplicate JOIN sourcelist ON ((sourcelist.sourcelist_id = specimenreplicate.institution_id))) JOIN sourcename USING (sourcelist_id)) GROUP BY specimenreplicate.source_id, sourcename.name, sourcename.matched_source_id) s JOIN source dataprovider ON ((dataprovider.source_id = s.dataprovider_id))) LEFT JOIN source dataset ON ((dataset.source_id = s.dataset_id))) ORDER BY dataprovider.shortname, s.records DESC, s.dataset);


--
-- Name: range_modeling_input; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW range_modeling_input AS
    SELECT analytical_stem.datasource AS source, analytical_stem."institutionCode" AS first_publisher, analytical_stem."decimalLatitude" AS latitude_deg, analytical_stem."decimalLongitude" AS longitude_deg, analytical_stem.geovalid_bien AS geovalid, analytical_stem."speciesBinomialWithMorphospecies" AS species_taxon_name, analytical_stem."higherPlantGroup_bien" AS higher_plant_group FROM analytical_stem WHERE (analytical_stem."higherPlantGroup_bien" IS NOT NULL);


--
-- Name: revision; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE revision (
    revision_id integer NOT NULL,
    tablename text NOT NULL,
    tableattribute text NOT NULL,
    tablerecord integer NOT NULL,
    previousvaluetext text NOT NULL,
    previousvaluetype text NOT NULL,
    previousrevision_id integer,
    revisiondate date NOT NULL
);


--
-- Name: revision_revision_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE revision_revision_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: revision_revision_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE revision_revision_id_seq OWNED BY revision.revision_id;


--
-- Name: revision_revision_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: soilsample; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE soilsample (
    soilsample_id integer NOT NULL,
    locationevent_id integer NOT NULL,
    horizon text DEFAULT 'unknown'::text NOT NULL,
    description text,
    depthtop_m double precision,
    depthbottom_m double precision,
    color text,
    texture text,
    organic_fraction double precision,
    sand_fraction double precision,
    silt_fraction double precision,
    clay_fraction double precision,
    coarse_fraction double precision,
    ph double precision,
    acidity_fraction double precision,
    basesaturation_fraction double precision,
    cationexchangecapacity_cmol_kg double precision,
    conductivity double precision,
    carbon_fraction double precision,
    phosphorus_fraction double precision,
    potassium_fraction double precision,
    magnesium_fraction double precision,
    nitrogen_fraction double precision,
    calcium_fraction double precision,
    sodium_fraction double precision
);


--
-- Name: soilsample_soilsample_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE soilsample_soilsample_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: soilsample_soilsample_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE soilsample_soilsample_id_seq OWNED BY soilsample.soilsample_id;


--
-- Name: soilsample_soilsample_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: soiltaxon; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE soiltaxon (
    soiltaxon_id integer NOT NULL,
    soilcode text,
    soilname text,
    soillevel integer,
    soilparent_id integer,
    soilframework text
);


--
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE soiltaxon_soiltaxon_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE soiltaxon_soiltaxon_id_seq OWNED BY soiltaxon.soiltaxon_id;


--
-- Name: soiltaxon_soiltaxon_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: source_source_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE source_source_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: source_source_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE source_source_id_seq OWNED BY source.source_id;


--
-- Name: source_source_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: sourcecontributor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE sourcecontributor (
    sourcecontributor_id integer NOT NULL,
    source_id integer NOT NULL,
    sourceparty_id integer NOT NULL,
    role role,
    "order" integer
);


--
-- Name: sourcecontributor_sourcecontributor_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE sourcecontributor_sourcecontributor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: sourcecontributor_sourcecontributor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE sourcecontributor_sourcecontributor_id_seq OWNED BY sourcecontributor.sourcecontributor_id;


--
-- Name: sourcecontributor_sourcecontributor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: sourcelist_sourcelist_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE sourcelist_sourcelist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: sourcelist_sourcelist_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE sourcelist_sourcelist_id_seq OWNED BY sourcelist.sourcelist_id;


--
-- Name: sourcelist_sourcelist_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: specimen; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE specimen (
    specimen_id integer NOT NULL
);


--
-- Name: TABLE specimen; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE specimen IS 'A physical specimen collected from a plant. Used to link replicates of the same specimen together.';


--
-- Name: specimen_specimen_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE specimen_specimen_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: specimen_specimen_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE specimen_specimen_id_seq OWNED BY specimen.specimen_id;


--
-- Name: specimen_specimen_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: specimenreplicate_specimenreplicate_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE specimenreplicate_specimenreplicate_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: specimenreplicate_specimenreplicate_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE specimenreplicate_specimenreplicate_id_seq OWNED BY specimenreplicate.specimenreplicate_id;


--
-- Name: specimenreplicate_specimenreplicate_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: stemobservation_stemobservation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE stemobservation_stemobservation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: stemobservation_stemobservation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE stemobservation_stemobservation_id_seq OWNED BY stemobservation.stemobservation_id;


--
-- Name: stemobservation_stemobservation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: stratum_stratum_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE stratum_stratum_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: stratum_stratum_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE stratum_stratum_id_seq OWNED BY stratum.stratum_id;


--
-- Name: stratum_stratum_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxon_trait; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxon_trait (
    "scientificName" text NOT NULL,
    "measurementType" text NOT NULL,
    "measurementValue" text,
    "measurementUnit" text
);


--
-- Name: TABLE taxon_trait; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE taxon_trait IS 'to export:
select * from taxon_trait order by "scientificName", "measurementType"';


--
-- Name: trait; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE trait (
    trait_id integer NOT NULL,
    taxonoccurrence_id integer NOT NULL,
    name text NOT NULL,
    value text,
    units text
);


--
-- Name: taxon_trait_view; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW taxon_trait_view AS
    SELECT COALESCE("ScrubbedTaxon"."acceptedTaxonName", "ScrubbedTaxon"."matchedTaxonName", taxonverbatim.taxonname, taxonverbatim.taxonomicname, taxonlabel.taxonomicname) AS "scientificName", trait.name AS "measurementType", trait.value AS "measurementValue", trait.units AS "measurementUnit" FROM (((((trait LEFT JOIN taxonoccurrence USING (taxonoccurrence_id)) LEFT JOIN taxondetermination ON (((taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id) AND taxondetermination.iscurrent))) LEFT JOIN taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel USING (taxonlabel_id)) LEFT JOIN "TNRS"."ScrubbedTaxon" ON (("ScrubbedTaxon"."concatenatedScientificName" = taxonlabel.taxonomicname)));


--
-- Name: taxonalt; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonalt (
    taxonalt_id integer NOT NULL,
    taxondetermination_id integer NOT NULL,
    taxonlabel_id integer NOT NULL,
    taxonaltfit text,
    taxonaltconfidence text,
    taxonaltnotes text
);


--
-- Name: taxonalt_taxonalt_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxonalt_taxonalt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxonalt_taxonalt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxonalt_taxonalt_id_seq OWNED BY taxonalt.taxonalt_id;


--
-- Name: taxonalt_taxonalt_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxonconcept; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonconcept (
    taxonlabel_id integer NOT NULL,
    concept_reference_id integer
);


--
-- Name: TABLE taxonconcept; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE taxonconcept IS 'A circumscribed taxon concept. This extends taxonlabel with information about who the taxon concept is according to.';


--
-- Name: COLUMN taxonconcept.concept_reference_id; Type: COMMENT; Schema: public; Owner: -
--

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

Equivalent to "Name sec. x".';


--
-- Name: taxonconcept_taxonlabel_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxonconcept_taxonlabel_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxonconcept_taxonlabel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxonconcept_taxonlabel_id_seq OWNED BY taxonconcept.taxonlabel_id;


--
-- Name: taxonconcept_taxonlabel_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxoncorrelation; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxoncorrelation (
    taxoncorrelation_id integer NOT NULL,
    taxonstatus_id integer NOT NULL,
    taxonlabel_id integer NOT NULL,
    plantconvergence text NOT NULL,
    correlationstart date NOT NULL,
    correlationstop date
);


--
-- Name: taxoncorrelation_taxoncorrelation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxoncorrelation_taxoncorrelation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxoncorrelation_taxoncorrelation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxoncorrelation_taxoncorrelation_id_seq OWNED BY taxoncorrelation.taxoncorrelation_id;


--
-- Name: taxoncorrelation_taxoncorrelation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxondetermination_taxondetermination_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxondetermination_taxondetermination_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxondetermination_taxondetermination_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxondetermination_taxondetermination_id_seq OWNED BY taxondetermination.taxondetermination_id;


--
-- Name: taxondetermination_taxondetermination_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxonlabel_relationship; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonlabel_relationship (
    descendant_id integer NOT NULL,
    ancestor_id integer NOT NULL,
    relationship relationship DEFAULT 'is included in'::relationship NOT NULL
);


--
-- Name: TABLE taxonlabel_relationship; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE taxonlabel_relationship IS 'Stores the accepted ancestors of a taxonlabel. Auto-populated, so should not be manually modified.';


--
-- Name: COLUMN taxonlabel_relationship.relationship; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN taxonlabel_relationship.relationship IS 'The type of relationship.';


--
-- Name: taxonlabel_taxonlabel_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxonlabel_taxonlabel_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxonlabel_taxonlabel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxonlabel_taxonlabel_id_seq OWNED BY taxonlabel.taxonlabel_id;


--
-- Name: taxonlabel_taxonlabel_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxonlineage; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonlineage (
    taxonlineage_id integer NOT NULL,
    childtaxonstatus_id integer NOT NULL,
    parenttaxonstatus_id integer NOT NULL
);


--
-- Name: taxonlineage_taxonlineage_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxonlineage_taxonlineage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxonlineage_taxonlineage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxonlineage_taxonlineage_id_seq OWNED BY taxonlineage.taxonlineage_id;


--
-- Name: taxonlineage_taxonlineage_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxonoccurrence_taxonoccurrence_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxonoccurrence_taxonoccurrence_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxonoccurrence_taxonoccurrence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxonoccurrence_taxonoccurrence_id_seq OWNED BY taxonoccurrence.taxonoccurrence_id;


--
-- Name: taxonoccurrence_taxonoccurrence_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxonstatus; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE taxonstatus (
    taxonstatus_id integer NOT NULL,
    taxonlabel_id integer NOT NULL,
    party_id integer,
    taxonlabelstatus text DEFAULT 'undetermined'::text NOT NULL,
    source_id integer,
    plantpartycomments text,
    startdate date,
    stopdate date
);


--
-- Name: taxonstatus_taxonstatus_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxonstatus_taxonstatus_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxonstatus_taxonstatus_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxonstatus_taxonstatus_id_seq OWNED BY taxonstatus.taxonstatus_id;


--
-- Name: taxonstatus_taxonstatus_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: taxonverbatim_taxonverbatim_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE taxonverbatim_taxonverbatim_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: taxonverbatim_taxonverbatim_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE taxonverbatim_taxonverbatim_id_seq OWNED BY taxonverbatim.taxonverbatim_id;


--
-- Name: taxonverbatim_taxonverbatim_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: telephone; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE telephone (
    telephone_id integer NOT NULL,
    party_id integer NOT NULL,
    phonenumber text NOT NULL,
    phonetype text NOT NULL
);


--
-- Name: telephone_telephone_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE telephone_telephone_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: telephone_telephone_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE telephone_telephone_id_seq OWNED BY telephone.telephone_id;


--
-- Name: telephone_telephone_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: threatened_taxonlabel_view; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW threatened_taxonlabel_view AS
    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));


--
-- Name: tnrs_input_name; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW tnrs_input_name AS
    WITH "AcceptedTaxon" AS (SELECT DISTINCT "MatchedTaxon"."acceptedScientificName" AS taxonomicname FROM ("TNRS"."MatchedTaxon" LEFT JOIN "TNRS"."AcceptedTaxon" ON (("AcceptedTaxon"."acceptedScientificName" = "MatchedTaxon"."acceptedScientificName"))) WHERE (("MatchedTaxon"."acceptedScientificName" IS NOT NULL) AND ("AcceptedTaxon"."acceptedScientificName" IS NULL))) SELECT "AcceptedTaxon".taxonomicname FROM "AcceptedTaxon" UNION ALL (SELECT DISTINCT taxonlabel.taxonomicname FROM (taxonlabel LEFT JOIN "TNRS"."MatchedTaxon" ON (("MatchedTaxon"."concatenatedScientificName" = taxonlabel.taxonomicname))) WHERE ((taxonlabel.taxonomicname IS NOT NULL) AND ("MatchedTaxon"."concatenatedScientificName" IS NULL)) EXCEPT SELECT "AcceptedTaxon".taxonomicname FROM "AcceptedTaxon");


--
-- Name: trait_trait_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE trait_trait_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: trait_trait_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE trait_trait_id_seq OWNED BY trait.trait_id;


--
-- Name: trait_trait_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: userdefined; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE userdefined (
    userdefined_id integer NOT NULL,
    userdefinedname text NOT NULL,
    userdefinedmetadata text,
    userdefinedcategory text,
    userdefinedtype text DEFAULT 'text'::text NOT NULL,
    tablename text NOT NULL
);


--
-- Name: userdefined_userdefined_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE userdefined_userdefined_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: userdefined_userdefined_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE userdefined_userdefined_id_seq OWNED BY userdefined.userdefined_id;


--
-- Name: userdefined_userdefined_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: voucher; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE voucher (
    voucher_id integer NOT NULL,
    taxonoccurrence_id integer NOT NULL,
    specimenreplicate_id integer NOT NULL
);


--
-- Name: voucher_voucher_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE voucher_voucher_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: voucher_voucher_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE voucher_voucher_id_seq OWNED BY voucher.voucher_id;


--
-- Name: voucher_voucher_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--



--
-- Name: address_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY address ALTER COLUMN address_id SET DEFAULT nextval('address_address_id_seq'::regclass);


--
-- Name: aggregateoccurrence_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY aggregateoccurrence ALTER COLUMN aggregateoccurrence_id SET DEFAULT nextval('aggregateoccurrence_aggregateoccurrence_id_seq'::regclass);


--
-- Name: classcontributor_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY classcontributor ALTER COLUMN classcontributor_id SET DEFAULT nextval('classcontributor_classcontributor_id_seq'::regclass);


--
-- Name: commclass_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commclass ALTER COLUMN commclass_id SET DEFAULT nextval('commclass_commclass_id_seq'::regclass);


--
-- Name: commconcept_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commconcept ALTER COLUMN commconcept_id SET DEFAULT nextval('commconcept_commconcept_id_seq'::regclass);


--
-- Name: commcorrelation_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commcorrelation ALTER COLUMN commcorrelation_id SET DEFAULT nextval('commcorrelation_commcorrelation_id_seq'::regclass);


--
-- Name: commdetermination_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commdetermination ALTER COLUMN commdetermination_id SET DEFAULT nextval('commdetermination_commdetermination_id_seq'::regclass);


--
-- Name: commlineage_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commlineage ALTER COLUMN commlineage_id SET DEFAULT nextval('commlineage_commlineage_id_seq'::regclass);


--
-- Name: commname_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commname ALTER COLUMN commname_id SET DEFAULT nextval('commname_commname_id_seq'::regclass);


--
-- Name: commstatus_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commstatus ALTER COLUMN commstatus_id SET DEFAULT nextval('commstatus_commstatus_id_seq'::regclass);


--
-- Name: commusage_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY commusage ALTER COLUMN commusage_id SET DEFAULT nextval('commusage_commusage_id_seq'::regclass);


--
-- Name: coordinates_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY coordinates ALTER COLUMN coordinates_id SET DEFAULT nextval('coordinates_coordinates_id_seq'::regclass);


--
-- Name: coverindex_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY coverindex ALTER COLUMN coverindex_id SET DEFAULT nextval('coverindex_coverindex_id_seq'::regclass);


--
-- Name: covermethod_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY covermethod ALTER COLUMN covermethod_id SET DEFAULT nextval('covermethod_covermethod_id_seq'::regclass);


--
-- Name: definedvalue_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY definedvalue ALTER COLUMN definedvalue_id SET DEFAULT nextval('definedvalue_definedvalue_id_seq'::regclass);


--
-- Name: disturbanceobs_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY disturbanceobs ALTER COLUMN disturbanceobs_id SET DEFAULT nextval('disturbanceobs_disturbanceobs_id_seq'::regclass);


--
-- Name: graphic_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY graphic ALTER COLUMN graphic_id SET DEFAULT nextval('graphic_graphic_id_seq'::regclass);


--
-- Name: location_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY location ALTER COLUMN location_id SET DEFAULT nextval('location_location_id_seq'::regclass);


--
-- Name: locationevent_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent ALTER COLUMN locationevent_id SET DEFAULT nextval('locationevent_locationevent_id_seq'::regclass);


--
-- Name: locationeventcontributor_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationeventcontributor ALTER COLUMN locationeventcontributor_id SET DEFAULT nextval('locationeventcontributor_locationeventcontributor_id_seq'::regclass);


--
-- Name: locationeventsynonym_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationeventsynonym ALTER COLUMN locationeventsynonym_id SET DEFAULT nextval('locationeventsynonym_locationeventsynonym_id_seq'::regclass);


--
-- Name: locationplace_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationplace ALTER COLUMN locationplace_id SET DEFAULT nextval('locationplace_locationplace_id_seq'::regclass);


--
-- Name: method_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY method ALTER COLUMN method_id SET DEFAULT nextval('method_method_id_seq'::regclass);


--
-- Name: methodtaxonclass_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY methodtaxonclass ALTER COLUMN methodtaxonclass_id SET DEFAULT nextval('methodtaxonclass_methodtaxonclass_id_seq'::regclass);


--
-- Name: note_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY note ALTER COLUMN note_id SET DEFAULT nextval('note_note_id_seq'::regclass);


--
-- Name: notelink_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY notelink ALTER COLUMN notelink_id SET DEFAULT nextval('notelink_notelink_id_seq'::regclass);


--
-- Name: party_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY party ALTER COLUMN party_id SET DEFAULT nextval('party_party_id_seq'::regclass);


--
-- Name: partymember_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY partymember ALTER COLUMN partymember_id SET DEFAULT nextval('partymember_partymember_id_seq'::regclass);


--
-- Name: place_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY place ALTER COLUMN place_id SET DEFAULT nextval('place_place_id_seq'::regclass);


--
-- Name: placecorrelation_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY placecorrelation ALTER COLUMN placecorrelation_id SET DEFAULT nextval('placecorrelation_placecorrelation_id_seq'::regclass);


--
-- Name: placename_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY placename ALTER COLUMN placename_id SET DEFAULT nextval('placename_placename_id_seq'::regclass);


--
-- Name: plant_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY plant ALTER COLUMN plant_id SET DEFAULT nextval('plant_plant_id_seq'::regclass);


--
-- Name: plantobservation_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY plantobservation ALTER COLUMN plantobservation_id SET DEFAULT nextval('plantobservation_plantobservation_id_seq'::regclass);


--
-- Name: project_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY project ALTER COLUMN project_id SET DEFAULT nextval('project_project_id_seq'::regclass);


--
-- Name: projectcontributor_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY projectcontributor ALTER COLUMN projectcontributor_id SET DEFAULT nextval('projectcontributor_projectcontributor_id_seq'::regclass);


--
-- Name: revision_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY revision ALTER COLUMN revision_id SET DEFAULT nextval('revision_revision_id_seq'::regclass);


--
-- Name: soilsample_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY soilsample ALTER COLUMN soilsample_id SET DEFAULT nextval('soilsample_soilsample_id_seq'::regclass);


--
-- Name: soiltaxon_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY soiltaxon ALTER COLUMN soiltaxon_id SET DEFAULT nextval('soiltaxon_soiltaxon_id_seq'::regclass);


--
-- Name: source_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY source ALTER COLUMN source_id SET DEFAULT nextval('source_source_id_seq'::regclass);


--
-- Name: sourcecontributor_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sourcecontributor ALTER COLUMN sourcecontributor_id SET DEFAULT nextval('sourcecontributor_sourcecontributor_id_seq'::regclass);


--
-- Name: sourcelist_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY sourcelist ALTER COLUMN sourcelist_id SET DEFAULT nextval('sourcelist_sourcelist_id_seq'::regclass);


--
-- Name: specimen_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY specimen ALTER COLUMN specimen_id SET DEFAULT nextval('specimen_specimen_id_seq'::regclass);


--
-- Name: specimenreplicate_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY specimenreplicate ALTER COLUMN specimenreplicate_id SET DEFAULT nextval('specimenreplicate_specimenreplicate_id_seq'::regclass);


--
-- Name: stemobservation_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY stemobservation ALTER COLUMN stemobservation_id SET DEFAULT nextval('stemobservation_stemobservation_id_seq'::regclass);


--
-- Name: stratum_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY stratum ALTER COLUMN stratum_id SET DEFAULT nextval('stratum_stratum_id_seq'::regclass);


--
-- Name: taxonalt_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonalt ALTER COLUMN taxonalt_id SET DEFAULT nextval('taxonalt_taxonalt_id_seq'::regclass);


--
-- Name: taxoncorrelation_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxoncorrelation ALTER COLUMN taxoncorrelation_id SET DEFAULT nextval('taxoncorrelation_taxoncorrelation_id_seq'::regclass);


--
-- Name: taxondetermination_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxondetermination ALTER COLUMN taxondetermination_id SET DEFAULT nextval('taxondetermination_taxondetermination_id_seq'::regclass);


--
-- Name: taxonlabel_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlabel ALTER COLUMN taxonlabel_id SET DEFAULT nextval('taxonlabel_taxonlabel_id_seq'::regclass);


--
-- Name: taxonlineage_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlineage ALTER COLUMN taxonlineage_id SET DEFAULT nextval('taxonlineage_taxonlineage_id_seq'::regclass);


--
-- Name: taxonoccurrence_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonoccurrence ALTER COLUMN taxonoccurrence_id SET DEFAULT nextval('taxonoccurrence_taxonoccurrence_id_seq'::regclass);


--
-- Name: taxonstatus_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonstatus ALTER COLUMN taxonstatus_id SET DEFAULT nextval('taxonstatus_taxonstatus_id_seq'::regclass);


--
-- Name: taxonverbatim_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonverbatim ALTER COLUMN taxonverbatim_id SET DEFAULT nextval('taxonverbatim_taxonverbatim_id_seq'::regclass);


--
-- Name: telephone_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY telephone ALTER COLUMN telephone_id SET DEFAULT nextval('telephone_telephone_id_seq'::regclass);


--
-- Name: trait_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY trait ALTER COLUMN trait_id SET DEFAULT nextval('trait_trait_id_seq'::regclass);


--
-- Name: userdefined_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY userdefined ALTER COLUMN userdefined_id SET DEFAULT nextval('userdefined_userdefined_id_seq'::regclass);


--
-- Name: voucher_id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY voucher ALTER COLUMN voucher_id SET DEFAULT nextval('voucher_voucher_id_seq'::regclass);


--
-- Data for Name: address; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: aggregateoccurrence; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: analytical_stem; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: classcontributor; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commclass; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commconcept; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commcorrelation; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commdetermination; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commlineage; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commname; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commstatus; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: commusage; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: coordinates; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: coverindex; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: covermethod; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: cultivated_family_locations; Type: TABLE DATA; Schema: public; Owner: -
--

INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Costa Rica');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Panama');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Colombia');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Venezuela');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Ecuador');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Peru');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Bolivia');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Chile');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Argentina');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Paraguay');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Uruguay');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Brazil');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Guyana');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'French Guiana');
INSERT INTO cultivated_family_locations VALUES ('Pinus', 'Suriname');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Venezuela');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Ecuador');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Peru');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Bolivia');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Chile');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Argentina');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Paraguay');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Uruguay');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Brazil');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Guyana');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'French Guiana');
INSERT INTO cultivated_family_locations VALUES ('Quercus', 'Suriname');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Nicaragua');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Costa Rica');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Panama');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Colombia');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Venezuela');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Ecuador');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Peru');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Bolivia');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Chile');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Argentina');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Paraguay');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Uruguay');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Brazil');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Guyana');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'French Guiana');
INSERT INTO cultivated_family_locations VALUES ('Acer', 'Suriname');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Nicaragua');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Costa Rica');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Panama');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Colombia');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Venezuela');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Ecuador');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Peru');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Bolivia');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Chile');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Argentina');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Paraguay');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Uruguay');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Brazil');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Guyana');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'French Guiana');
INSERT INTO cultivated_family_locations VALUES ('Abies', 'Suriname');
INSERT INTO cultivated_family_locations VALUES ('Arecaceae', 'Canada');


--
-- Data for Name: definedvalue; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: disturbanceobs; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: family_higher_plant_group; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: geoscrub_input; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: graphic; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: higher_plant_group_nodes; Type: TABLE DATA; Schema: public; Owner: -
--

INSERT INTO higher_plant_group_nodes VALUES ('bryophytes', 'Anthocerotophyta');
INSERT INTO higher_plant_group_nodes VALUES ('bryophytes', 'Marchantiophyta');
INSERT INTO higher_plant_group_nodes VALUES ('bryophytes', 'Bryophyta');
INSERT INTO higher_plant_group_nodes VALUES ('ferns and allies', 'Lycopodiophyta');
INSERT INTO higher_plant_group_nodes VALUES ('ferns and allies', 'Moniliformopses');
INSERT INTO higher_plant_group_nodes VALUES ('flowering plants', 'Magnoliophyta');
INSERT INTO higher_plant_group_nodes VALUES ('gymnosperms (conifers)', 'Coniferophyta');
INSERT INTO higher_plant_group_nodes VALUES ('gymnosperms (non-conifer)', 'Cycadophyta');
INSERT INTO higher_plant_group_nodes VALUES ('gymnosperms (non-conifer)', 'Ginkgophyta');
INSERT INTO higher_plant_group_nodes VALUES ('gymnosperms (non-conifer)', 'Gnetophyta');
INSERT INTO higher_plant_group_nodes VALUES (NULL, 'root');


--
-- Data for Name: location; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: locationevent; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: locationeventcontributor; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: locationeventsynonym; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: locationplace; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: method; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: methodtaxonclass; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: note; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: notelink; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: party; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: partymember; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: place; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: placecorrelation; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: placename; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: placename_ancestor; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: plant; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: plantobservation; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: project; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: projectcontributor; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: provider_count; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: revision; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: soilsample; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: soiltaxon; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: source; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: sourcecontributor; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: sourcelist; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: sourcename; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: specimen; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: specimenreplicate; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: stemobservation; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: stratum; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxon_trait; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonalt; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonconcept; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxoncorrelation; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxondetermination; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonlabel; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonlabel_relationship; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonlineage; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonoccurrence; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonstatus; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: taxonverbatim; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: telephone; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: threatened_taxonlabel; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: trait; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: userdefined; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Data for Name: voucher; Type: TABLE DATA; Schema: public; Owner: -
--



--
-- Name: address_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY address
    ADD CONSTRAINT address_pkey PRIMARY KEY (address_id);


--
-- Name: aggregateoccurrence_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY aggregateoccurrence
    ADD CONSTRAINT aggregateoccurrence_pkey PRIMARY KEY (aggregateoccurrence_id);


--
-- Name: classcontributor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY classcontributor
    ADD CONSTRAINT classcontributor_pkey PRIMARY KEY (classcontributor_id);


--
-- Name: commclass_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commclass
    ADD CONSTRAINT commclass_pkey PRIMARY KEY (commclass_id);


--
-- Name: commconcept_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commconcept
    ADD CONSTRAINT commconcept_pkey PRIMARY KEY (commconcept_id);


--
-- Name: commconcept_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commconcept
    ADD CONSTRAINT commconcept_unique UNIQUE (commname_id);


--
-- Name: commcorrelation_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commcorrelation
    ADD CONSTRAINT commcorrelation_pkey PRIMARY KEY (commcorrelation_id);


--
-- Name: commdetermination_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commdetermination
    ADD CONSTRAINT commdetermination_pkey PRIMARY KEY (commdetermination_id);


--
-- Name: commdetermination_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commdetermination
    ADD CONSTRAINT commdetermination_unique UNIQUE (commclass_id, commconcept_id);


--
-- Name: commlineage_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commlineage
    ADD CONSTRAINT commlineage_pkey PRIMARY KEY (commlineage_id);


--
-- Name: commname_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commname
    ADD CONSTRAINT commname_pkey PRIMARY KEY (commname_id);


--
-- Name: commname_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commname
    ADD CONSTRAINT commname_unique UNIQUE (commname);


--
-- Name: commstatus_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commstatus
    ADD CONSTRAINT commstatus_pkey PRIMARY KEY (commstatus_id);


--
-- Name: commusage_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY commusage
    ADD CONSTRAINT commusage_pkey PRIMARY KEY (commusage_id);


--
-- Name: coordinates_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY coordinates
    ADD CONSTRAINT coordinates_pkey PRIMARY KEY (coordinates_id);


--
-- Name: coverindex_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY coverindex
    ADD CONSTRAINT coverindex_pkey PRIMARY KEY (coverindex_id);


--
-- Name: covermethod_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY covermethod
    ADD CONSTRAINT covermethod_pkey PRIMARY KEY (covermethod_id);


--
-- Name: cultivated_family_locations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY cultivated_family_locations
    ADD CONSTRAINT cultivated_family_locations_pkey PRIMARY KEY (family, country);


--
-- Name: definedvalue_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY definedvalue
    ADD CONSTRAINT definedvalue_pkey PRIMARY KEY (definedvalue_id);


--
-- Name: definedvalue_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY definedvalue
    ADD CONSTRAINT definedvalue_unique UNIQUE (userdefined_id, tablerecord_id);


--
-- Name: disturbanceobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY disturbanceobs
    ADD CONSTRAINT disturbanceobs_pkey PRIMARY KEY (disturbanceobs_id);


--
-- Name: family_higher_plant_group_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY family_higher_plant_group
    ADD CONSTRAINT family_higher_plant_group_pkey PRIMARY KEY (family);


--
-- Name: graphic_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY graphic
    ADD CONSTRAINT graphic_pkey PRIMARY KEY (graphic_id);


--
-- Name: location_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY location
    ADD CONSTRAINT location_pkey PRIMARY KEY (location_id);


--
-- Name: locationevent_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_pkey PRIMARY KEY (locationevent_id);


--
-- Name: locationeventcontributor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY locationeventcontributor
    ADD CONSTRAINT locationeventcontributor_pkey PRIMARY KEY (locationeventcontributor_id);


--
-- Name: locationeventcontributor_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY locationeventcontributor
    ADD CONSTRAINT locationeventcontributor_unique UNIQUE (locationevent_id, party_id);


--
-- Name: locationeventsynonym_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY locationeventsynonym
    ADD CONSTRAINT locationeventsynonym_pkey PRIMARY KEY (locationeventsynonym_id);


--
-- Name: locationplace_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY locationplace
    ADD CONSTRAINT locationplace_pkey PRIMARY KEY (locationplace_id);


--
-- Name: method_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY method
    ADD CONSTRAINT method_pkey PRIMARY KEY (method_id);


--
-- Name: methodtaxonclass_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY methodtaxonclass
    ADD CONSTRAINT methodtaxonclass_pkey PRIMARY KEY (methodtaxonclass_id);


--
-- Name: methodtaxonclass_unique_description; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY methodtaxonclass
    ADD CONSTRAINT methodtaxonclass_unique_description UNIQUE (method_id, taxonclass);


--
-- Name: methodtaxonclass_unique_taxonlabel_id; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY methodtaxonclass
    ADD CONSTRAINT methodtaxonclass_unique_taxonlabel_id UNIQUE (method_id, taxonlabel_id);


--
-- Name: note_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY note
    ADD CONSTRAINT note_pkey PRIMARY KEY (note_id);


--
-- Name: notelink_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY notelink
    ADD CONSTRAINT notelink_pkey PRIMARY KEY (notelink_id);


--
-- Name: party_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY party
    ADD CONSTRAINT party_pkey PRIMARY KEY (party_id);


--
-- Name: partymember_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY partymember
    ADD CONSTRAINT partymember_pkey PRIMARY KEY (partymember_id);


--
-- Name: place_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY place
    ADD CONSTRAINT place_pkey PRIMARY KEY (place_id);


--
-- Name: placecorrelation_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY placecorrelation
    ADD CONSTRAINT placecorrelation_pkey PRIMARY KEY (placecorrelation_id);


--
-- Name: placename_ancestor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY placename_ancestor
    ADD CONSTRAINT placename_ancestor_pkey PRIMARY KEY (placename_id, ancestor_id);


--
-- Name: placename_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY placename
    ADD CONSTRAINT placename_pkey PRIMARY KEY (placename_id);


--
-- Name: plant_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY plant
    ADD CONSTRAINT plant_pkey PRIMARY KEY (plant_id);


--
-- Name: plantobservation_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY plantobservation
    ADD CONSTRAINT plantobservation_pkey PRIMARY KEY (plantobservation_id);


--
-- Name: project_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY project
    ADD CONSTRAINT project_pkey PRIMARY KEY (project_id);


--
-- Name: project_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY project
    ADD CONSTRAINT project_unique UNIQUE (source_id, projectname);


--
-- Name: projectcontributor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY projectcontributor
    ADD CONSTRAINT projectcontributor_pkey PRIMARY KEY (projectcontributor_id);


--
-- Name: provider_count_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY provider_count
    ADD CONSTRAINT provider_count_pkey PRIMARY KEY (dataprovider, dataset);


--
-- Name: revision_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY revision
    ADD CONSTRAINT revision_pkey PRIMARY KEY (revision_id);


--
-- Name: soilsample_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY soilsample
    ADD CONSTRAINT soilsample_pkey PRIMARY KEY (soilsample_id);


--
-- Name: soilsample_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY soilsample
    ADD CONSTRAINT soilsample_unique UNIQUE (locationevent_id);


--
-- Name: soiltaxon_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY soiltaxon
    ADD CONSTRAINT soiltaxon_pkey PRIMARY KEY (soiltaxon_id);


--
-- Name: source_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY source
    ADD CONSTRAINT source_pkey PRIMARY KEY (source_id);


--
-- Name: sourcecontributor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY sourcecontributor
    ADD CONSTRAINT sourcecontributor_pkey PRIMARY KEY (sourcecontributor_id);


--
-- Name: sourcelist_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY sourcelist
    ADD CONSTRAINT sourcelist_pkey PRIMARY KEY (sourcelist_id);


--
-- Name: sourcename_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY sourcename
    ADD CONSTRAINT sourcename_pkey PRIMARY KEY (sourcelist_id, name);


--
-- Name: specimen_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY specimen
    ADD CONSTRAINT specimen_pkey PRIMARY KEY (specimen_id);


--
-- Name: specimenreplicate_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY specimenreplicate
    ADD CONSTRAINT specimenreplicate_pkey PRIMARY KEY (specimenreplicate_id);


--
-- Name: stemobservation_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY stemobservation
    ADD CONSTRAINT stemobservation_pkey PRIMARY KEY (stemobservation_id);


--
-- Name: stratum_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY stratum
    ADD CONSTRAINT stratum_pkey PRIMARY KEY (stratum_id);


--
-- Name: stratum_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY stratum
    ADD CONSTRAINT stratum_unique UNIQUE (source_id, stratumname);


--
-- Name: taxonalt_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonalt
    ADD CONSTRAINT taxonalt_pkey PRIMARY KEY (taxonalt_id);


--
-- Name: taxonconcept_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonconcept
    ADD CONSTRAINT taxonconcept_pkey PRIMARY KEY (taxonlabel_id);


--
-- Name: taxoncorrelation_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxoncorrelation
    ADD CONSTRAINT taxoncorrelation_pkey PRIMARY KEY (taxoncorrelation_id);


--
-- Name: taxondetermination_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxondetermination
    ADD CONSTRAINT taxondetermination_pkey PRIMARY KEY (taxondetermination_id);


--
-- Name: taxonlabel_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonlabel
    ADD CONSTRAINT taxonlabel_pkey PRIMARY KEY (taxonlabel_id);


--
-- Name: taxonlabel_relationship_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonlabel_relationship
    ADD CONSTRAINT taxonlabel_relationship_pkey PRIMARY KEY (descendant_id, ancestor_id);


--
-- Name: taxonlineage_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonlineage
    ADD CONSTRAINT taxonlineage_pkey PRIMARY KEY (taxonlineage_id);


--
-- Name: taxonoccurrence_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonoccurrence
    ADD CONSTRAINT taxonoccurrence_pkey PRIMARY KEY (taxonoccurrence_id);


--
-- Name: taxonstatus_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonstatus
    ADD CONSTRAINT taxonstatus_pkey PRIMARY KEY (taxonstatus_id);


--
-- Name: taxonstatus_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonstatus
    ADD CONSTRAINT taxonstatus_unique UNIQUE (taxonlabel_id, party_id);


--
-- Name: taxonverbatim_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY taxonverbatim
    ADD CONSTRAINT taxonverbatim_pkey PRIMARY KEY (taxonverbatim_id);


--
-- Name: telephone_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY telephone
    ADD CONSTRAINT telephone_pkey PRIMARY KEY (telephone_id);


--
-- Name: threatened_taxonlabel_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY threatened_taxonlabel
    ADD CONSTRAINT threatened_taxonlabel_pkey PRIMARY KEY (taxonlabel_id);


--
-- Name: trait_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY trait
    ADD CONSTRAINT trait_pkey PRIMARY KEY (trait_id);


--
-- Name: userdefined_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY userdefined
    ADD CONSTRAINT userdefined_pkey PRIMARY KEY (userdefined_id);


--
-- Name: userdefined_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY userdefined
    ADD CONSTRAINT userdefined_unique UNIQUE (tablename, userdefinedname);


--
-- Name: voucher_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY voucher
    ADD CONSTRAINT voucher_pkey PRIMARY KEY (voucher_id);


--
-- Name: voucher_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY voucher
    ADD CONSTRAINT voucher_unique UNIQUE (taxonoccurrence_id, specimenreplicate_id);


--
-- Name: address_organization_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX address_organization_id_idx ON address USING btree (organization_id);


--
-- Name: address_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX address_party_id_idx ON address USING btree (party_id);


--
-- Name: aggregateoccurrence_coverindex_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX aggregateoccurrence_coverindex_id_idx ON aggregateoccurrence USING btree (coverindex_id);


--
-- Name: aggregateoccurrence_method_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX aggregateoccurrence_method_id_idx ON aggregateoccurrence USING btree (method_id);


--
-- Name: aggregateoccurrence_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX aggregateoccurrence_source_id_idx ON aggregateoccurrence USING btree (source_id);


--
-- Name: aggregateoccurrence_stratum_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX aggregateoccurrence_stratum_id_idx ON aggregateoccurrence USING btree (stratum_id);


--
-- Name: aggregateoccurrence_taxonoccurrence; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX aggregateoccurrence_taxonoccurrence ON aggregateoccurrence USING btree (taxonoccurrence_id);


--
-- Name: aggregateoccurrence_taxonoccurrence_1_to_1; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX aggregateoccurrence_taxonoccurrence_1_to_1 ON aggregateoccurrence USING btree (taxonoccurrence_id) WHERE (sourceaccessioncode IS NULL);


--
-- Name: aggregateoccurrence_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: analytical_stem_datasource_institutionCode_collectionCode_c_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX "analytical_stem_datasource_institutionCode_collectionCode_c_idx" ON analytical_stem USING btree (datasource, "institutionCode", "collectionCode", "catalogNumber");


--
-- Name: analytical_stem_datasource_occurrenceID_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX "analytical_stem_datasource_occurrenceID_idx" ON analytical_stem USING btree (datasource, "occurrenceID");


--
-- Name: analytical_stem_datasource_projectID_locationID_dateCollect_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX "analytical_stem_datasource_projectID_locationID_dateCollect_idx" ON analytical_stem USING btree (datasource, "projectID", "locationID", "dateCollected");


--
-- Name: classcontributor_commclass_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX classcontributor_commclass_id_idx ON classcontributor USING btree (commclass_id);


--
-- Name: classcontributor_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX classcontributor_party_id_idx ON classcontributor USING btree (party_id);


--
-- Name: commclass_classpublication_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commclass_classpublication_id_idx ON commclass USING btree (classpublication_id);


--
-- Name: commclass_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX commclass_unique ON commclass USING btree (locationevent_id, (COALESCE(classnotes, '\N'::text)));


--
-- Name: commconcept_reference_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commconcept_reference_id_idx ON commconcept USING btree (reference_id);


--
-- Name: commcorrelation_commconcept_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commcorrelation_commconcept_id_idx ON commcorrelation USING btree (commconcept_id);


--
-- Name: commcorrelation_commstatus_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commcorrelation_commstatus_id_idx ON commcorrelation USING btree (commstatus_id);


--
-- Name: commdetermination_commauthority_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commdetermination_commauthority_id_idx ON commdetermination USING btree (commauthority_id);


--
-- Name: commdetermination_commconcept_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commdetermination_commconcept_id_idx ON commdetermination USING btree (commconcept_id);


--
-- Name: commlineage_childcommstatus_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commlineage_childcommstatus_id_idx ON commlineage USING btree (childcommstatus_id);


--
-- Name: commlineage_parentcommstatus_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commlineage_parentcommstatus_id_idx ON commlineage USING btree (parentcommstatus_id);


--
-- Name: commname_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commname_source_id_idx ON commname USING btree (source_id);


--
-- Name: commstatus_commconcept_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commstatus_commconcept_id_idx ON commstatus USING btree (commconcept_id);


--
-- Name: commstatus_commparent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commstatus_commparent_id_idx ON commstatus USING btree (commparent_id);


--
-- Name: commstatus_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commstatus_party_id_idx ON commstatus USING btree (party_id);


--
-- Name: commstatus_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commstatus_source_id_idx ON commstatus USING btree (source_id);


--
-- Name: commusage_commconcept_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commusage_commconcept_id_idx ON commusage USING btree (commconcept_id);


--
-- Name: commusage_commname_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commusage_commname_id_idx ON commusage USING btree (commname_id);


--
-- Name: commusage_commstatus_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commusage_commstatus_id_idx ON commusage USING btree (commstatus_id);


--
-- Name: commusage_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX commusage_party_id_idx ON commusage USING btree (party_id);


--
-- Name: coordinates_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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)));


--
-- Name: coverindex_covermethod_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX coverindex_covermethod_id_idx ON coverindex USING btree (covermethod_id);


--
-- Name: covermethod_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX covermethod_source_id_idx ON covermethod USING btree (source_id);


--
-- Name: disturbanceobs_locationevent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX disturbanceobs_locationevent_id_idx ON disturbanceobs USING btree (locationevent_id);


--
-- Name: graphic_locationevent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX graphic_locationevent_id_idx ON graphic USING btree (locationevent_id);


--
-- Name: higher_plant_group_nodes_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX higher_plant_group_nodes_unique ON higher_plant_group_nodes USING btree ((COALESCE(higher_plant_group, 'all'::higher_plant_group)), node_name);


--
-- Name: location_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX location_creator ON location USING btree (source_id);


--
-- Name: location_parent; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX location_parent ON location USING btree (parent_id);


--
-- Name: location_unique_within_creator_by_authorlocationcode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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));


--
-- Name: location_unique_within_creator_by_sourceaccessioncode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: location_unique_within_parent_by_authorlocationcode_position; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX location_unique_within_parent_by_authorlocationcode_position ON location USING btree ((COALESCE(parent_id, 2147483647)), (COALESCE(authorlocationcode, '\N'::text)), (COALESCE(sublocationxposition_m, 'NaN'::double precision)), (COALESCE(sublocationyposition_m, 'NaN'::double precision))) WHERE ((parent_id IS NOT NULL) AND (authorlocationcode IS NOT NULL));


--
-- Name: locationevent__stratum_id; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent__stratum_id ON locationevent USING btree (stratum_id);


--
-- Name: locationevent_location; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent_location ON locationevent USING btree (location_id);


--
-- Name: locationevent_method_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent_method_id_idx ON locationevent USING btree (method_id);


--
-- Name: locationevent_parent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent_parent_id_idx ON locationevent USING btree (parent_id);


--
-- Name: locationevent_previous_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent_previous_id_idx ON locationevent USING btree (previous_id);


--
-- Name: locationevent_project_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent_project_id_idx ON locationevent USING btree (project_id);


--
-- Name: locationevent_soiltaxon_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent_soiltaxon_id_idx ON locationevent USING btree (soiltaxon_id);


--
-- Name: locationevent_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationevent_source_id_idx ON locationevent USING btree (source_id);


--
-- Name: locationevent_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: locationevent_unique_within_location; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX locationevent_unique_within_location ON locationevent USING btree ((COALESCE(location_id, 2147483647)), (COALESCE(authoreventcode, '\N'::text)), (COALESCE(obsstartdate, 'infinity'::date)), (COALESCE(stratum_id, 2147483647))) WHERE ((parent_id IS NULL) AND (sourceaccessioncode IS NULL));


--
-- Name: locationevent_unique_within_parent_by_authoreventcode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX locationevent_unique_within_parent_by_authoreventcode ON locationevent USING btree ((COALESCE(parent_id, 2147483647)), (COALESCE(authoreventcode, '\N'::text)), (COALESCE(stratum_id, 2147483647))) WHERE ((parent_id IS NOT NULL) AND (authoreventcode IS NOT NULL));


--
-- Name: locationevent_unique_within_parent_by_location; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX locationevent_unique_within_parent_by_location ON locationevent USING btree ((COALESCE(parent_id, 2147483647)), location_id, (COALESCE(stratum_id, 2147483647))) WHERE (parent_id IS NOT NULL);


--
-- Name: locationevent_unique_within_project; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX locationevent_unique_within_project ON locationevent USING btree ((COALESCE(project_id, 2147483647)), (COALESCE(authoreventcode, '\N'::text)), (COALESCE(obsstartdate, 'infinity'::date)), (COALESCE(stratum_id, 2147483647))) WHERE ((((parent_id IS NULL) AND (project_id IS NOT NULL)) AND (authoreventcode IS NOT NULL)) AND (obsstartdate IS NOT NULL));


--
-- Name: locationeventcontributor_locationevent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationeventcontributor_locationevent_id_idx ON locationeventcontributor USING btree (locationevent_id);


--
-- Name: locationeventcontributor_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationeventcontributor_party_id_idx ON locationeventcontributor USING btree (party_id);


--
-- Name: locationeventsynonym_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationeventsynonym_party_id_idx ON locationeventsynonym USING btree (party_id);


--
-- Name: locationeventsynonym_primarylocationevent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationeventsynonym_primarylocationevent_id_idx ON locationeventsynonym USING btree (primarylocationevent_id);


--
-- Name: locationeventsynonym_synonymlocationevent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationeventsynonym_synonymlocationevent_id_idx ON locationeventsynonym USING btree (synonymlocationevent_id);


--
-- Name: locationplace_identifier_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationplace_identifier_id_idx ON locationplace USING btree (identifier_id);


--
-- Name: locationplace_place_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX locationplace_place_id_idx ON locationplace USING btree (place_id);


--
-- Name: locationplace_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX locationplace_unique ON locationplace USING btree (location_id, place_id, (COALESCE(identifier_id, 2147483647)));


--
-- Name: method_covermethod_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX method_covermethod_id_idx ON method USING btree (covermethod_id);


--
-- Name: method_subplotmethod_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX method_subplotmethod_id_idx ON method USING btree (subplotmethod_id);


--
-- Name: method_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: methodtaxonclass_submethod_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX methodtaxonclass_submethod_id_idx ON methodtaxonclass USING btree (submethod_id);


--
-- Name: methodtaxonclass_taxonlabel_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX methodtaxonclass_taxonlabel_id_idx ON methodtaxonclass USING btree (taxonlabel_id);


--
-- Name: note_notelink_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX note_notelink_id_idx ON note USING btree (notelink_id);


--
-- Name: note_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX note_party_id_idx ON note USING btree (party_id);


--
-- Name: party_currentname_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX party_currentname_id_idx ON party USING btree (currentname_id);


--
-- Name: party_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX party_source_id_idx ON party USING btree (source_id);


--
-- Name: party_unique_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX party_unique_name 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))) WHERE (sourceaccessioncode IS NULL);


--
-- Name: party_unique_sourceaccessioncode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX party_unique_sourceaccessioncode ON party USING btree (source_id, (COALESCE(sourceaccessioncode, '\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);


--
-- Name: partymember_childparty_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX partymember_childparty_id_idx ON partymember USING btree (childparty_id);


--
-- Name: partymember_parentparty_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX partymember_parentparty_id_idx ON partymember USING btree (parentparty_id);


--
-- Name: place_canon_place_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX place_canon_place_id_idx ON place USING btree (canon_place_id);


--
-- Name: place_coordinates_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX place_coordinates_id_idx ON place USING btree (coordinates_id);


--
-- Name: place_matched_place_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX place_matched_place_id_idx ON place USING btree (matched_place_id);


--
-- Name: place_placename_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX place_placename_id_idx ON place USING btree (placename_id);


--
-- Name: place_unique_within_creator_by_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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)));


--
-- Name: placecorrelation_childplace_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX placecorrelation_childplace_id_idx ON placecorrelation USING btree (childplace_id);


--
-- Name: placecorrelation_parentplace_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX placecorrelation_parentplace_id_idx ON placecorrelation USING btree (parentplace_id);


--
-- Name: placename_ancestor_ancestor_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX placename_ancestor_ancestor_id_idx ON placename_ancestor USING btree (ancestor_id);


--
-- Name: placename_parent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX placename_parent_id_idx ON placename USING btree (parent_id);


--
-- Name: placename_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX placename_unique ON placename USING btree ((COALESCE(parent_id, 2147483647)), placename, rank);


--
-- Name: plantobservation_aggregateoccurrence_1_to_1; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX plantobservation_aggregateoccurrence_1_to_1 ON plantobservation USING btree (aggregateoccurrence_id);


--
-- Name: plantobservation_plant_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX plantobservation_plant_id_idx ON plantobservation USING btree (plant_id);


--
-- Name: plantobservation_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX plantobservation_source_id_idx ON plantobservation USING btree (source_id);


--
-- Name: plantobservation_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: project_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX project_source_id_idx ON project USING btree (source_id);


--
-- Name: project_unique_name_date; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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);


--
-- Name: project_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: projectcontributor_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX projectcontributor_party_id_idx ON projectcontributor USING btree (party_id);


--
-- Name: projectcontributor_project_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX projectcontributor_project_id_idx ON projectcontributor USING btree (project_id);


--
-- Name: revision_previousrevision_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX revision_previousrevision_id_idx ON revision USING btree (previousrevision_id);


--
-- Name: soiltaxon_soilparent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX soiltaxon_soilparent_id_idx ON soiltaxon USING btree (soilparent_id);


--
-- Name: source_matched_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX source_matched_source_id_idx ON source USING btree (matched_source_id);


--
-- Name: source_parent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX source_parent_id_idx ON source USING btree (parent_id);


--
-- Name: source_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX source_unique ON source USING btree (shortname);


--
-- Name: sourcecontributor_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX sourcecontributor_source_id_idx ON sourcecontributor USING btree (source_id);


--
-- Name: sourcecontributor_sourceparty_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX sourcecontributor_sourceparty_id_idx ON sourcecontributor USING btree (sourceparty_id);


--
-- Name: sourcelist_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX sourcelist_unique ON sourcelist USING btree (source_id, name);


--
-- Name: sourcename_matched_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX sourcename_matched_source_id_idx ON sourcename USING btree (matched_source_id);


--
-- Name: specimenreplicate_institution_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX specimenreplicate_institution_id_idx ON specimenreplicate USING btree (institution_id);


--
-- Name: specimenreplicate_plantobservation; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX specimenreplicate_plantobservation ON specimenreplicate USING btree (plantobservation_id);


--
-- Name: specimenreplicate_plantobservation_1_to_1; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX specimenreplicate_plantobservation_1_to_1 ON specimenreplicate USING btree ((COALESCE(plantobservation_id, 2147483647))) WHERE (((plantobservation_id IS NOT NULL) AND (sourceaccessioncode IS NULL)) AND (catalognumber_dwc IS NULL));


--
-- Name: specimenreplicate_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX specimenreplicate_source_id_idx ON specimenreplicate USING btree (source_id);


--
-- Name: specimenreplicate_specimen_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX specimenreplicate_specimen_id_idx ON specimenreplicate USING btree (specimen_id);


--
-- Name: specimenreplicate_unique_catalognumber; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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));


--
-- Name: specimenreplicate_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: stemobservation_plantobservation_1_to_1; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX stemobservation_plantobservation_1_to_1 ON stemobservation USING btree (plantobservation_id) WHERE ((sourceaccessioncode IS NULL) AND (authorstemcode IS NULL));


--
-- Name: stemobservation_plantobservation_id; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX stemobservation_plantobservation_id ON stemobservation USING btree (plantobservation_id);


--
-- Name: stemobservation_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX stemobservation_source_id_idx ON stemobservation USING btree (source_id);


--
-- Name: stemobservation_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: stemobservation_unique_within_plantobservation; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX stemobservation_unique_within_plantobservation ON stemobservation USING btree (plantobservation_id, (COALESCE(authorstemcode, '\N'::text)), (COALESCE(tag, '\N'::text))) WHERE (sourceaccessioncode IS NULL);


--
-- Name: stratum_method_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX stratum_method_id_idx ON stratum USING btree (method_id);


--
-- Name: taxon_trait_scientificName_measurementType_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX "taxon_trait_scientificName_measurementType_idx" ON taxon_trait USING btree ("scientificName", "measurementType");


--
-- Name: taxonalt_taxondetermination_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonalt_taxondetermination_id_idx ON taxonalt USING btree (taxondetermination_id);


--
-- Name: taxonalt_taxonlabel_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonalt_taxonlabel_id_idx ON taxonalt USING btree (taxonlabel_id);


--
-- Name: taxonconcept_concept_reference_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonconcept_concept_reference_id_idx ON taxonconcept USING btree (concept_reference_id);


--
-- Name: taxoncorrelation_taxonlabel_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxoncorrelation_taxonlabel_id_idx ON taxoncorrelation USING btree (taxonlabel_id);


--
-- Name: taxoncorrelation_taxonstatus_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxoncorrelation_taxonstatus_id_idx ON taxoncorrelation USING btree (taxonstatus_id);


--
-- Name: taxondetermination_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxondetermination_party_id_idx ON taxondetermination USING btree (party_id);


--
-- Name: taxondetermination_reference_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxondetermination_reference_id_idx ON taxondetermination USING btree (reference_id);


--
-- Name: taxondetermination_single_accepted_determination; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX taxondetermination_single_accepted_determination ON taxondetermination USING btree (taxonoccurrence_id) WHERE (determinationtype = 'accepted'::text);


--
-- Name: taxondetermination_single_current_determination; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX taxondetermination_single_current_determination ON taxondetermination USING btree (taxonoccurrence_id) WHERE iscurrent;


--
-- Name: taxondetermination_single_matched_determination; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX taxondetermination_single_matched_determination ON taxondetermination USING btree (taxonoccurrence_id) WHERE (determinationtype = 'matched'::text);


--
-- Name: taxondetermination_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxondetermination_source_id_idx ON taxondetermination USING btree (source_id);


--
-- Name: taxondetermination_taxonverbatim_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxondetermination_taxonverbatim_id_idx ON taxondetermination USING btree (taxonverbatim_id);


--
-- Name: taxondetermination_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX taxondetermination_unique ON taxondetermination USING btree (taxonoccurrence_id, source_id, (COALESCE(determinationtype, '\N'::text)), isoriginal, role, (COALESCE(party_id, 2147483647)), taxonverbatim_id);


--
-- Name: taxonlabel_0_unique_identifying_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: taxonlabel_1_unique_sourceaccessioncode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: taxonlabel_canon_label_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonlabel_canon_label_id_idx ON taxonlabel USING btree (canon_label_id);


--
-- Name: taxonlabel_matched_label_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonlabel_matched_label_id_idx ON taxonlabel USING btree (matched_label_id);


--
-- Name: taxonlabel_parent_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonlabel_parent_id_idx ON taxonlabel USING btree (parent_id);


--
-- Name: taxonlabel_relationship_descendants; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonlabel_relationship_descendants ON taxonlabel_relationship USING btree (ancestor_id, descendant_id);


--
-- Name: taxonlabel_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonlabel_source_id_idx ON taxonlabel USING btree (source_id);


--
-- Name: taxonlabel_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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)));


--
-- Name: taxonlineage_childtaxonstatus_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonlineage_childtaxonstatus_id_idx ON taxonlineage USING btree (childtaxonstatus_id);


--
-- Name: taxonlineage_parenttaxonstatus_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonlineage_parenttaxonstatus_id_idx ON taxonlineage USING btree (parenttaxonstatus_id);


--
-- Name: taxonoccurrence_collector_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonoccurrence_collector_id_idx ON taxonoccurrence USING btree (collector_id);


--
-- Name: taxonoccurrence_locationevent; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonoccurrence_locationevent ON taxonoccurrence USING btree (locationevent_id);


--
-- Name: taxonoccurrence_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonoccurrence_source_id_idx ON taxonoccurrence USING btree (source_id);


--
-- Name: taxonoccurrence_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: taxonoccurrence_unique_within_locationevent; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX taxonoccurrence_unique_within_locationevent ON taxonoccurrence USING btree ((COALESCE(locationevent_id, 2147483647)), (COALESCE(authortaxoncode, '\N'::text))) WHERE (sourceaccessioncode IS NULL);


--
-- Name: taxonstatus_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonstatus_party_id_idx ON taxonstatus USING btree (party_id);


--
-- Name: taxonstatus_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonstatus_source_id_idx ON taxonstatus USING btree (source_id);


--
-- Name: taxonverbatim_source_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonverbatim_source_id_idx ON taxonverbatim USING btree (source_id);


--
-- Name: taxonverbatim_taxonlabel_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX taxonverbatim_taxonlabel_id_idx ON taxonverbatim USING btree (taxonlabel_id);


--
-- Name: taxonverbatim_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX taxonverbatim_unique ON taxonverbatim USING btree ((COALESCE(taxonlabel_id, 2147483647)), (COALESCE(morphospecies, '\N'::text)), (COALESCE(morphoname, '\N'::text)));


--
-- Name: telephone_party_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX telephone_party_id_idx ON telephone USING btree (party_id);


--
-- Name: trait_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX trait_unique ON trait USING btree (taxonoccurrence_id, name);


--
-- Name: voucher_specimenreplicate_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX voucher_specimenreplicate_id_idx ON voucher USING btree (specimenreplicate_id);


--
-- Name: locationevent__pull_forward_from_parent; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER locationevent__pull_forward_from_parent BEFORE INSERT OR UPDATE OF locationevent_id, parent_id ON locationevent FOR EACH ROW WHEN (((new.parent_id IS NOT NULL) AND (new.stratum_id IS NOT NULL))) EXECUTE PROCEDURE locationevent__pull_forward_from_parent();


--
-- Name: party_source_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
--

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


--
-- Name: place_matched_place_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER place_matched_place_id_self_ref BEFORE INSERT OR UPDATE ON place FOR EACH ROW EXECUTE PROCEDURE place_matched_place_id_self_ref();


--
-- Name: place_set_canon_place_id_on_insert; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER place_set_canon_place_id_on_insert BEFORE INSERT ON place FOR EACH ROW EXECUTE PROCEDURE place_set_canon_place_id_on_insert();


--
-- Name: place_set_canon_place_id_on_update; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER place_set_canon_place_id_on_update BEFORE UPDATE ON place FOR EACH ROW EXECUTE PROCEDURE place_set_canon_place_id_on_update();


--
-- Name: placename_update_ancestors; Type: TRIGGER; Schema: public; Owner: -
--

CREATE CONSTRAINT TRIGGER placename_update_ancestors AFTER INSERT OR UPDATE ON placename DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE placename_update_ancestors();


--
-- Name: plantobservation_aggregateoccurrence_count_1; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER plantobservation_aggregateoccurrence_count_1 AFTER INSERT OR UPDATE ON plantobservation FOR EACH ROW EXECUTE PROCEDURE plantobservation_aggregateoccurrence_count_1();


--
-- Name: sourcename_set_matched_source_id; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER sourcename_set_matched_source_id BEFORE INSERT OR UPDATE ON sourcename FOR EACH ROW EXECUTE PROCEDURE sourcename_set_matched_source_id();


--
-- Name: taxondetermination_set_iscurrent_on_delete; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxondetermination_set_iscurrent_on_delete AFTER DELETE ON taxondetermination FOR EACH ROW EXECUTE PROCEDURE taxondetermination_set_iscurrent_on_delete();


--
-- Name: taxondetermination_set_iscurrent_on_insert; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxondetermination_set_iscurrent_on_insert AFTER INSERT ON taxondetermination FOR EACH ROW EXECUTE PROCEDURE taxondetermination_set_iscurrent_on_insert();


--
-- Name: taxonlabel_0_matched_label_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxonlabel_0_matched_label_id_self_ref BEFORE INSERT OR UPDATE ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_0_matched_label_id_self_ref();


--
-- Name: taxonlabel_2_set_canon_label_id_on_insert; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxonlabel_2_set_canon_label_id_on_insert BEFORE INSERT ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_2_set_canon_label_id_on_insert();


--
-- Name: taxonlabel_2_set_canon_label_id_on_update; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxonlabel_2_set_canon_label_id_on_update BEFORE UPDATE ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_2_set_canon_label_id_on_update();


--
-- Name: taxonlabel_3_parent_id_avoid_self_ref; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxonlabel_3_parent_id_avoid_self_ref BEFORE INSERT OR UPDATE ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_3_parent_id_avoid_self_ref();


--
-- Name: taxonlabel_update_ancestors_on_insert; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxonlabel_update_ancestors_on_insert AFTER INSERT ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_update_ancestors_on_insert();


--
-- Name: taxonlabel_update_ancestors_on_update; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER taxonlabel_update_ancestors_on_update AFTER UPDATE ON taxonlabel FOR EACH ROW EXECUTE PROCEDURE taxonlabel_update_ancestors_on_update();


--
-- Name: address_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY address
    ADD CONSTRAINT address_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: address_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY address
    ADD CONSTRAINT address_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: aggregateoccurrence_coverindex_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY aggregateoccurrence
    ADD CONSTRAINT aggregateoccurrence_coverindex_id_fkey FOREIGN KEY (coverindex_id) REFERENCES coverindex(coverindex_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- Name: aggregateoccurrence_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY aggregateoccurrence
    ADD CONSTRAINT aggregateoccurrence_method_id_fkey FOREIGN KEY (method_id) REFERENCES method(method_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: aggregateoccurrence_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY aggregateoccurrence
    ADD CONSTRAINT aggregateoccurrence_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: aggregateoccurrence_stratum_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY aggregateoccurrence
    ADD CONSTRAINT aggregateoccurrence_stratum_id_fkey FOREIGN KEY (stratum_id) REFERENCES stratum(stratum_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: aggregateoccurrence_taxonoccurrence_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY aggregateoccurrence
    ADD CONSTRAINT aggregateoccurrence_taxonoccurrence_id_fkey FOREIGN KEY (taxonoccurrence_id) REFERENCES taxonoccurrence(taxonoccurrence_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: analytical_stem_datasource_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY analytical_stem
    ADD CONSTRAINT analytical_stem_datasource_fkey FOREIGN KEY (datasource) REFERENCES source(shortname) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: classcontributor_commclass_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY classcontributor
    ADD CONSTRAINT classcontributor_commclass_id_fkey FOREIGN KEY (commclass_id) REFERENCES commclass(commclass_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: classcontributor_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY classcontributor
    ADD CONSTRAINT classcontributor_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commclass_classpublication_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: commclass_locationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commclass
    ADD CONSTRAINT commclass_locationevent_id_fkey FOREIGN KEY (locationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commconcept_commname_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commconcept
    ADD CONSTRAINT commconcept_commname_id_fkey FOREIGN KEY (commname_id) REFERENCES commname(commname_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commconcept_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: commcorrelation_commconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commcorrelation
    ADD CONSTRAINT commcorrelation_commconcept_id_fkey FOREIGN KEY (commconcept_id) REFERENCES commconcept(commconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commcorrelation_commstatus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commcorrelation
    ADD CONSTRAINT commcorrelation_commstatus_id_fkey FOREIGN KEY (commstatus_id) REFERENCES commstatus(commstatus_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commdetermination_commauthority_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: commdetermination_commclass_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commdetermination
    ADD CONSTRAINT commdetermination_commclass_id_fkey FOREIGN KEY (commclass_id) REFERENCES commclass(commclass_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commdetermination_commconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commdetermination
    ADD CONSTRAINT commdetermination_commconcept_id_fkey FOREIGN KEY (commconcept_id) REFERENCES commconcept(commconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commlineage_childcommstatus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commlineage
    ADD CONSTRAINT commlineage_childcommstatus_id_fkey FOREIGN KEY (childcommstatus_id) REFERENCES commstatus(commstatus_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commlineage_parentcommstatus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commlineage
    ADD CONSTRAINT commlineage_parentcommstatus_id_fkey FOREIGN KEY (parentcommstatus_id) REFERENCES commstatus(commstatus_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commname_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commname
    ADD CONSTRAINT commname_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commstatus_commconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commstatus
    ADD CONSTRAINT commstatus_commconcept_id_fkey FOREIGN KEY (commconcept_id) REFERENCES commconcept(commconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commstatus_commparent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commstatus
    ADD CONSTRAINT commstatus_commparent_id_fkey FOREIGN KEY (commparent_id) REFERENCES commconcept(commconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commstatus_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commstatus
    ADD CONSTRAINT commstatus_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commstatus_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commstatus
    ADD CONSTRAINT commstatus_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commusage_commconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commusage
    ADD CONSTRAINT commusage_commconcept_id_fkey FOREIGN KEY (commconcept_id) REFERENCES commconcept(commconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commusage_commname_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commusage
    ADD CONSTRAINT commusage_commname_id_fkey FOREIGN KEY (commname_id) REFERENCES commname(commname_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commusage_commstatus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commusage
    ADD CONSTRAINT commusage_commstatus_id_fkey FOREIGN KEY (commstatus_id) REFERENCES commstatus(commstatus_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: commusage_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY commusage
    ADD CONSTRAINT commusage_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: coordinates_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY coordinates
    ADD CONSTRAINT coordinates_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: coverindex_covermethod_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY coverindex
    ADD CONSTRAINT coverindex_covermethod_id_fkey FOREIGN KEY (covermethod_id) REFERENCES covermethod(covermethod_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: covermethod_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY covermethod
    ADD CONSTRAINT covermethod_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: definedvalue_userdefined_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY definedvalue
    ADD CONSTRAINT definedvalue_userdefined_id_fkey FOREIGN KEY (userdefined_id) REFERENCES userdefined(userdefined_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: disturbanceobs_locationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY disturbanceobs
    ADD CONSTRAINT disturbanceobs_locationevent_id_fkey FOREIGN KEY (locationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: graphic_locationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY graphic
    ADD CONSTRAINT graphic_locationevent_id_fkey FOREIGN KEY (locationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: location_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY location
    ADD CONSTRAINT location_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES location(location_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: location_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY location
    ADD CONSTRAINT location_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_location_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_location_id_fkey FOREIGN KEY (location_id) REFERENCES location(location_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_method_id_fkey FOREIGN KEY (method_id) REFERENCES method(method_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_previous_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_previous_id_fkey FOREIGN KEY (previous_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_project_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(project_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_soiltaxon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_soiltaxon_id_fkey FOREIGN KEY (soiltaxon_id) REFERENCES soiltaxon(soiltaxon_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationevent_stratum_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationevent
    ADD CONSTRAINT locationevent_stratum_id_fkey FOREIGN KEY (stratum_id) REFERENCES stratum(stratum_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationeventcontributor_locationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationeventcontributor
    ADD CONSTRAINT locationeventcontributor_locationevent_id_fkey FOREIGN KEY (locationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationeventcontributor_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationeventcontributor
    ADD CONSTRAINT locationeventcontributor_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationeventsynonym_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationeventsynonym
    ADD CONSTRAINT locationeventsynonym_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationeventsynonym_primarylocationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationeventsynonym
    ADD CONSTRAINT locationeventsynonym_primarylocationevent_id_fkey FOREIGN KEY (primarylocationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationeventsynonym_synonymlocationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationeventsynonym
    ADD CONSTRAINT locationeventsynonym_synonymlocationevent_id_fkey FOREIGN KEY (synonymlocationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationplace_identifier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationplace
    ADD CONSTRAINT locationplace_identifier_id_fkey FOREIGN KEY (identifier_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationplace_location_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationplace
    ADD CONSTRAINT locationplace_location_id_fkey FOREIGN KEY (location_id) REFERENCES location(location_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: locationplace_place_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY locationplace
    ADD CONSTRAINT locationplace_place_id_fkey FOREIGN KEY (place_id) REFERENCES place(place_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: method_covermethod_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY method
    ADD CONSTRAINT method_covermethod_id_fkey FOREIGN KEY (covermethod_id) REFERENCES covermethod(covermethod_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: method_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY method
    ADD CONSTRAINT method_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: method_subplotmethod_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY method
    ADD CONSTRAINT method_subplotmethod_id_fkey FOREIGN KEY (subplotmethod_id) REFERENCES method(method_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- Name: methodtaxonclass_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY methodtaxonclass
    ADD CONSTRAINT methodtaxonclass_method_id_fkey FOREIGN KEY (method_id) REFERENCES method(method_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: methodtaxonclass_submethod_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY methodtaxonclass
    ADD CONSTRAINT methodtaxonclass_submethod_id_fkey FOREIGN KEY (submethod_id) REFERENCES method(method_id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- Name: methodtaxonclass_taxonlabel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY methodtaxonclass
    ADD CONSTRAINT methodtaxonclass_taxonlabel_id_fkey FOREIGN KEY (taxonlabel_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: note_notelink_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY note
    ADD CONSTRAINT note_notelink_id_fkey FOREIGN KEY (notelink_id) REFERENCES notelink(notelink_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: note_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY note
    ADD CONSTRAINT note_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: party_currentname_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY party
    ADD CONSTRAINT party_currentname_id_fkey FOREIGN KEY (currentname_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: party_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY party
    ADD CONSTRAINT party_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: partymember_childparty_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY partymember
    ADD CONSTRAINT partymember_childparty_id_fkey FOREIGN KEY (childparty_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: partymember_parentparty_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY partymember
    ADD CONSTRAINT partymember_parentparty_id_fkey FOREIGN KEY (parentparty_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: place_canon_place_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY place
    ADD CONSTRAINT place_canon_place_id_fkey FOREIGN KEY (canon_place_id) REFERENCES place(place_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: place_coordinates_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY place
    ADD CONSTRAINT place_coordinates_id_fkey FOREIGN KEY (coordinates_id) REFERENCES coordinates(coordinates_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: place_matched_place_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY place
    ADD CONSTRAINT place_matched_place_id_fkey FOREIGN KEY (matched_place_id) REFERENCES place(place_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: place_placename_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY place
    ADD CONSTRAINT place_placename_id_fkey FOREIGN KEY (placename_id) REFERENCES placename(placename_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: place_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY place
    ADD CONSTRAINT place_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: placecorrelation_childplace_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY placecorrelation
    ADD CONSTRAINT placecorrelation_childplace_id_fkey FOREIGN KEY (childplace_id) REFERENCES placename(placename_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: placecorrelation_parentplace_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY placecorrelation
    ADD CONSTRAINT placecorrelation_parentplace_id_fkey FOREIGN KEY (parentplace_id) REFERENCES placename(placename_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: placename_ancestor_ancestor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY placename_ancestor
    ADD CONSTRAINT placename_ancestor_ancestor_id_fkey FOREIGN KEY (ancestor_id) REFERENCES placename(placename_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: placename_ancestor_place_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY placename_ancestor
    ADD CONSTRAINT placename_ancestor_place_id_fkey FOREIGN KEY (placename_id) REFERENCES placename(placename_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: placename_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY placename
    ADD CONSTRAINT placename_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES placename(placename_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: plantobservation_aggregateoccurrence_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY plantobservation
    ADD CONSTRAINT plantobservation_aggregateoccurrence_id_fkey FOREIGN KEY (aggregateoccurrence_id) REFERENCES aggregateoccurrence(aggregateoccurrence_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: plantobservation_plant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY plantobservation
    ADD CONSTRAINT plantobservation_plant_id_fkey FOREIGN KEY (plant_id) REFERENCES plant(plant_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: plantobservation_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY plantobservation
    ADD CONSTRAINT plantobservation_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: project_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY project
    ADD CONSTRAINT project_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: projectcontributor_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY projectcontributor
    ADD CONSTRAINT projectcontributor_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: projectcontributor_project_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY projectcontributor
    ADD CONSTRAINT projectcontributor_project_id_fkey FOREIGN KEY (project_id) REFERENCES project(project_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: revision_previousrevision_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY revision
    ADD CONSTRAINT revision_previousrevision_id_fkey FOREIGN KEY (previousrevision_id) REFERENCES revision(revision_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: soilsample_locationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY soilsample
    ADD CONSTRAINT soilsample_locationevent_id_fkey FOREIGN KEY (locationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: soiltaxon_soilparent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY soiltaxon
    ADD CONSTRAINT soiltaxon_soilparent_id_fkey FOREIGN KEY (soilparent_id) REFERENCES soiltaxon(soiltaxon_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: source_matched_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY source
    ADD CONSTRAINT source_matched_source_id_fkey FOREIGN KEY (matched_source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: source_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY source
    ADD CONSTRAINT source_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: sourcecontributor_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sourcecontributor
    ADD CONSTRAINT sourcecontributor_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: sourcecontributor_sourceparty_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sourcecontributor
    ADD CONSTRAINT sourcecontributor_sourceparty_id_fkey FOREIGN KEY (sourceparty_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: sourcelist_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sourcelist
    ADD CONSTRAINT sourcelist_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: sourcename_matched_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sourcename
    ADD CONSTRAINT sourcename_matched_source_id_fkey FOREIGN KEY (matched_source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: sourcename_sourcelist_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY sourcename
    ADD CONSTRAINT sourcename_sourcelist_id_fkey FOREIGN KEY (sourcelist_id) REFERENCES sourcelist(sourcelist_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: specimenreplicate_institution_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY specimenreplicate
    ADD CONSTRAINT specimenreplicate_institution_id_fkey FOREIGN KEY (institution_id) REFERENCES sourcelist(sourcelist_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: specimenreplicate_plantobservation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY specimenreplicate
    ADD CONSTRAINT specimenreplicate_plantobservation_id_fkey FOREIGN KEY (plantobservation_id) REFERENCES plantobservation(plantobservation_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: specimenreplicate_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY specimenreplicate
    ADD CONSTRAINT specimenreplicate_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: specimenreplicate_specimen_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY specimenreplicate
    ADD CONSTRAINT specimenreplicate_specimen_id_fkey FOREIGN KEY (specimen_id) REFERENCES specimen(specimen_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: stemobservation_plantobservation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY stemobservation
    ADD CONSTRAINT stemobservation_plantobservation_id_fkey FOREIGN KEY (plantobservation_id) REFERENCES plantobservation(plantobservation_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: stemobservation_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY stemobservation
    ADD CONSTRAINT stemobservation_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: stratum_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY stratum
    ADD CONSTRAINT stratum_method_id_fkey FOREIGN KEY (method_id) REFERENCES method(method_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: stratum_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY stratum
    ADD CONSTRAINT stratum_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonalt_taxondetermination_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonalt
    ADD CONSTRAINT taxonalt_taxondetermination_id_fkey FOREIGN KEY (taxondetermination_id) REFERENCES taxondetermination(taxondetermination_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonalt_taxonlabel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonalt
    ADD CONSTRAINT taxonalt_taxonlabel_id_fkey FOREIGN KEY (taxonlabel_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonconcept_concept_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonconcept
    ADD CONSTRAINT taxonconcept_concept_reference_id_fkey FOREIGN KEY (concept_reference_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonconcept_taxonlabel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonconcept
    ADD CONSTRAINT taxonconcept_taxonlabel_id_fkey FOREIGN KEY (taxonlabel_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxoncorrelation_taxonlabel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxoncorrelation
    ADD CONSTRAINT taxoncorrelation_taxonlabel_id_fkey FOREIGN KEY (taxonlabel_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxoncorrelation_taxonstatus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxoncorrelation
    ADD CONSTRAINT taxoncorrelation_taxonstatus_id_fkey FOREIGN KEY (taxonstatus_id) REFERENCES taxonstatus(taxonstatus_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxondetermination_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxondetermination
    ADD CONSTRAINT taxondetermination_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxondetermination_reference_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxondetermination
    ADD CONSTRAINT taxondetermination_reference_id_fkey FOREIGN KEY (reference_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxondetermination_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxondetermination
    ADD CONSTRAINT taxondetermination_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxondetermination_taxonoccurrence_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxondetermination
    ADD CONSTRAINT taxondetermination_taxonoccurrence_id_fkey FOREIGN KEY (taxonoccurrence_id) REFERENCES taxonoccurrence(taxonoccurrence_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxondetermination_taxonverbatim_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxondetermination
    ADD CONSTRAINT taxondetermination_taxonverbatim_id_fkey FOREIGN KEY (taxonverbatim_id) REFERENCES taxonverbatim(taxonverbatim_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlabel_canon_label_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlabel
    ADD CONSTRAINT taxonlabel_canon_label_id_fkey FOREIGN KEY (canon_label_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlabel_matched_label_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlabel
    ADD CONSTRAINT taxonlabel_matched_label_id_fkey FOREIGN KEY (matched_label_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlabel_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlabel
    ADD CONSTRAINT taxonlabel_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlabel_relationship_ancestor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlabel_relationship
    ADD CONSTRAINT taxonlabel_relationship_ancestor_id_fkey FOREIGN KEY (ancestor_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlabel_relationship_descendant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlabel_relationship
    ADD CONSTRAINT taxonlabel_relationship_descendant_id_fkey FOREIGN KEY (descendant_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlabel_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlabel
    ADD CONSTRAINT taxonlabel_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlineage_childtaxonstatus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlineage
    ADD CONSTRAINT taxonlineage_childtaxonstatus_id_fkey FOREIGN KEY (childtaxonstatus_id) REFERENCES taxonstatus(taxonstatus_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonlineage_parenttaxonstatus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonlineage
    ADD CONSTRAINT taxonlineage_parenttaxonstatus_id_fkey FOREIGN KEY (parenttaxonstatus_id) REFERENCES taxonstatus(taxonstatus_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonoccurrence_collector_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonoccurrence
    ADD CONSTRAINT taxonoccurrence_collector_id_fkey FOREIGN KEY (collector_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonoccurrence_locationevent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonoccurrence
    ADD CONSTRAINT taxonoccurrence_locationevent_id_fkey FOREIGN KEY (locationevent_id) REFERENCES locationevent(locationevent_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonoccurrence_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonoccurrence
    ADD CONSTRAINT taxonoccurrence_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonstatus_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonstatus
    ADD CONSTRAINT taxonstatus_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonstatus_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonstatus
    ADD CONSTRAINT taxonstatus_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonstatus_taxonlabel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonstatus
    ADD CONSTRAINT taxonstatus_taxonlabel_id_fkey FOREIGN KEY (taxonlabel_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonverbatim_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonverbatim
    ADD CONSTRAINT taxonverbatim_source_id_fkey FOREIGN KEY (source_id) REFERENCES source(source_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: taxonverbatim_taxonlabel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY taxonverbatim
    ADD CONSTRAINT taxonverbatim_taxonlabel_id_fkey FOREIGN KEY (taxonlabel_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: telephone_party_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY telephone
    ADD CONSTRAINT telephone_party_id_fkey FOREIGN KEY (party_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: threatened_taxonlabel_taxonlabel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY threatened_taxonlabel
    ADD CONSTRAINT threatened_taxonlabel_taxonlabel_id_fkey FOREIGN KEY (taxonlabel_id) REFERENCES taxonlabel(taxonlabel_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: trait_taxonoccurrence_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY trait
    ADD CONSTRAINT trait_taxonoccurrence_id_fkey FOREIGN KEY (taxonoccurrence_id) REFERENCES taxonoccurrence(taxonoccurrence_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: voucher_specimenreplicate_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY voucher
    ADD CONSTRAINT voucher_specimenreplicate_id_fkey FOREIGN KEY (specimenreplicate_id) REFERENCES specimenreplicate(specimenreplicate_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: voucher_taxonoccurrence_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY voucher
    ADD CONSTRAINT voucher_taxonoccurrence_id_fkey FOREIGN KEY (taxonoccurrence_id) REFERENCES taxonoccurrence(taxonoccurrence_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: public; Type: ACL; Schema: -; Owner: -
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM bien;
GRANT ALL ON SCHEMA public TO bien;
GRANT USAGE ON SCHEMA public TO bien_read;
GRANT USAGE ON SCHEMA public TO public_;


--
-- Name: source; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE source FROM PUBLIC;
REVOKE ALL ON TABLE source FROM bien;
GRANT ALL ON TABLE source TO bien;
GRANT SELECT ON TABLE source TO bien_read;
GRANT SELECT ON TABLE source TO public_;


--
-- Name: place; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE place FROM PUBLIC;
REVOKE ALL ON TABLE place FROM bien;
GRANT ALL ON TABLE place TO bien;
GRANT SELECT ON TABLE place TO bien_read;


--
-- Name: taxonlabel; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonlabel FROM PUBLIC;
REVOKE ALL ON TABLE taxonlabel FROM bien;
GRANT ALL ON TABLE taxonlabel TO bien;
GRANT SELECT ON TABLE taxonlabel TO bien_read;


--
-- Name: address; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE address FROM PUBLIC;
REVOKE ALL ON TABLE address FROM bien;
GRANT ALL ON TABLE address TO bien;
GRANT SELECT ON TABLE address TO bien_read;


--
-- Name: aggregateoccurrence; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE aggregateoccurrence FROM PUBLIC;
REVOKE ALL ON TABLE aggregateoccurrence FROM bien;
GRANT ALL ON TABLE aggregateoccurrence TO bien;
GRANT SELECT ON TABLE aggregateoccurrence TO bien_read;


--
-- Name: analytical_stem; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE analytical_stem FROM PUBLIC;
REVOKE ALL ON TABLE analytical_stem FROM bien;
GRANT ALL ON TABLE analytical_stem TO bien;
GRANT SELECT ON TABLE analytical_stem TO bien_read;


--
-- Name: analytical_plot; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE analytical_plot FROM PUBLIC;
REVOKE ALL ON TABLE analytical_plot FROM bien;
GRANT ALL ON TABLE analytical_plot TO bien;
GRANT SELECT ON TABLE analytical_plot TO bien_read;


--
-- Name: analytical_specimen; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE analytical_specimen FROM PUBLIC;
REVOKE ALL ON TABLE analytical_specimen FROM bien;
GRANT ALL ON TABLE analytical_specimen TO bien;
GRANT SELECT ON TABLE analytical_specimen TO bien_read;


--
-- Name: coordinates; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE coordinates FROM PUBLIC;
REVOKE ALL ON TABLE coordinates FROM bien;
GRANT ALL ON TABLE coordinates TO bien;
GRANT SELECT ON TABLE coordinates TO bien_read;


--
-- Name: cultivated_family_locations; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE cultivated_family_locations FROM PUBLIC;
REVOKE ALL ON TABLE cultivated_family_locations FROM bien;
GRANT ALL ON TABLE cultivated_family_locations TO bien;
GRANT SELECT ON TABLE cultivated_family_locations TO bien_read;
GRANT SELECT ON TABLE cultivated_family_locations TO public_;


--
-- Name: family_higher_plant_group; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE family_higher_plant_group FROM PUBLIC;
REVOKE ALL ON TABLE family_higher_plant_group FROM bien;
GRANT ALL ON TABLE family_higher_plant_group TO bien;
GRANT SELECT ON TABLE family_higher_plant_group TO bien_read;


--
-- Name: location; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE location FROM PUBLIC;
REVOKE ALL ON TABLE location FROM bien;
GRANT ALL ON TABLE location TO bien;
GRANT SELECT ON TABLE location TO bien_read;


--
-- Name: locationevent; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE locationevent FROM PUBLIC;
REVOKE ALL ON TABLE locationevent FROM bien;
GRANT ALL ON TABLE locationevent TO bien;
GRANT SELECT ON TABLE locationevent TO bien_read;


--
-- Name: locationplace; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE locationplace FROM PUBLIC;
REVOKE ALL ON TABLE locationplace FROM bien;
GRANT ALL ON TABLE locationplace TO bien;
GRANT SELECT ON TABLE locationplace TO bien_read;


--
-- Name: method; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE method FROM PUBLIC;
REVOKE ALL ON TABLE method FROM bien;
GRANT ALL ON TABLE method TO bien;
GRANT SELECT ON TABLE method TO bien_read;


--
-- Name: party; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE party FROM PUBLIC;
REVOKE ALL ON TABLE party FROM bien;
GRANT ALL ON TABLE party TO bien;
GRANT SELECT ON TABLE party TO bien_read;


--
-- Name: plantobservation; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE plantobservation FROM PUBLIC;
REVOKE ALL ON TABLE plantobservation FROM bien;
GRANT ALL ON TABLE plantobservation TO bien;
GRANT SELECT ON TABLE plantobservation TO bien_read;


--
-- Name: project; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE project FROM PUBLIC;
REVOKE ALL ON TABLE project FROM bien;
GRANT ALL ON TABLE project TO bien;
GRANT SELECT ON TABLE project TO bien_read;


--
-- Name: sourcelist; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE sourcelist FROM PUBLIC;
REVOKE ALL ON TABLE sourcelist FROM bien;
GRANT ALL ON TABLE sourcelist TO bien;
GRANT SELECT ON TABLE sourcelist TO bien_read;


--
-- Name: specimenreplicate; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE specimenreplicate FROM PUBLIC;
REVOKE ALL ON TABLE specimenreplicate FROM bien;
GRANT ALL ON TABLE specimenreplicate TO bien;
GRANT SELECT ON TABLE specimenreplicate TO bien_read;


--
-- Name: stemobservation; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE stemobservation FROM PUBLIC;
REVOKE ALL ON TABLE stemobservation FROM bien;
GRANT ALL ON TABLE stemobservation TO bien;
GRANT SELECT ON TABLE stemobservation TO bien_read;


--
-- Name: stratum; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE stratum FROM PUBLIC;
REVOKE ALL ON TABLE stratum FROM bien;
GRANT ALL ON TABLE stratum TO bien;
GRANT SELECT ON TABLE stratum TO bien_read;


--
-- Name: taxondetermination; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxondetermination FROM PUBLIC;
REVOKE ALL ON TABLE taxondetermination FROM bien;
GRANT ALL ON TABLE taxondetermination TO bien;
GRANT SELECT ON TABLE taxondetermination TO bien_read;


--
-- Name: taxonoccurrence; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonoccurrence FROM PUBLIC;
REVOKE ALL ON TABLE taxonoccurrence FROM bien;
GRANT ALL ON TABLE taxonoccurrence TO bien;
GRANT SELECT ON TABLE taxonoccurrence TO bien_read;


--
-- Name: taxonverbatim; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonverbatim FROM PUBLIC;
REVOKE ALL ON TABLE taxonverbatim FROM bien;
GRANT ALL ON TABLE taxonverbatim TO bien;
GRANT SELECT ON TABLE taxonverbatim TO bien_read;


--
-- Name: threatened_taxonlabel; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE threatened_taxonlabel FROM PUBLIC;
REVOKE ALL ON TABLE threatened_taxonlabel FROM bien;
GRANT ALL ON TABLE threatened_taxonlabel TO bien;
GRANT SELECT ON TABLE threatened_taxonlabel TO bien_read;


--
-- Name: analytical_stem_view; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE analytical_stem_view FROM PUBLIC;
REVOKE ALL ON TABLE analytical_stem_view FROM bien;
GRANT ALL ON TABLE analytical_stem_view TO bien;
GRANT SELECT ON TABLE analytical_stem_view TO bien_read;


--
-- Name: classcontributor; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE classcontributor FROM PUBLIC;
REVOKE ALL ON TABLE classcontributor FROM bien;
GRANT ALL ON TABLE classcontributor TO bien;
GRANT SELECT ON TABLE classcontributor TO bien_read;


--
-- Name: commclass; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commclass FROM PUBLIC;
REVOKE ALL ON TABLE commclass FROM bien;
GRANT ALL ON TABLE commclass TO bien;
GRANT SELECT ON TABLE commclass TO bien_read;


--
-- Name: commconcept; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commconcept FROM PUBLIC;
REVOKE ALL ON TABLE commconcept FROM bien;
GRANT ALL ON TABLE commconcept TO bien;
GRANT SELECT ON TABLE commconcept TO bien_read;


--
-- Name: commcorrelation; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commcorrelation FROM PUBLIC;
REVOKE ALL ON TABLE commcorrelation FROM bien;
GRANT ALL ON TABLE commcorrelation TO bien;
GRANT SELECT ON TABLE commcorrelation TO bien_read;


--
-- Name: commdetermination; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commdetermination FROM PUBLIC;
REVOKE ALL ON TABLE commdetermination FROM bien;
GRANT ALL ON TABLE commdetermination TO bien;
GRANT SELECT ON TABLE commdetermination TO bien_read;


--
-- Name: commlineage; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commlineage FROM PUBLIC;
REVOKE ALL ON TABLE commlineage FROM bien;
GRANT ALL ON TABLE commlineage TO bien;
GRANT SELECT ON TABLE commlineage TO bien_read;


--
-- Name: commname; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commname FROM PUBLIC;
REVOKE ALL ON TABLE commname FROM bien;
GRANT ALL ON TABLE commname TO bien;
GRANT SELECT ON TABLE commname TO bien_read;


--
-- Name: commstatus; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commstatus FROM PUBLIC;
REVOKE ALL ON TABLE commstatus FROM bien;
GRANT ALL ON TABLE commstatus TO bien;
GRANT SELECT ON TABLE commstatus TO bien_read;


--
-- Name: commusage; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE commusage FROM PUBLIC;
REVOKE ALL ON TABLE commusage FROM bien;
GRANT ALL ON TABLE commusage TO bien;
GRANT SELECT ON TABLE commusage TO bien_read;


--
-- Name: coverindex; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE coverindex FROM PUBLIC;
REVOKE ALL ON TABLE coverindex FROM bien;
GRANT ALL ON TABLE coverindex TO bien;
GRANT SELECT ON TABLE coverindex TO bien_read;


--
-- Name: covermethod; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE covermethod FROM PUBLIC;
REVOKE ALL ON TABLE covermethod FROM bien;
GRANT ALL ON TABLE covermethod TO bien;
GRANT SELECT ON TABLE covermethod TO bien_read;


--
-- Name: definedvalue; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE definedvalue FROM PUBLIC;
REVOKE ALL ON TABLE definedvalue FROM bien;
GRANT ALL ON TABLE definedvalue TO bien;
GRANT SELECT ON TABLE definedvalue TO bien_read;


--
-- Name: disturbanceobs; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE disturbanceobs FROM PUBLIC;
REVOKE ALL ON TABLE disturbanceobs FROM bien;
GRANT ALL ON TABLE disturbanceobs TO bien;
GRANT SELECT ON TABLE disturbanceobs TO bien_read;


--
-- Name: geoscrub_input; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE geoscrub_input FROM PUBLIC;
REVOKE ALL ON TABLE geoscrub_input FROM bien;
GRANT ALL ON TABLE geoscrub_input TO bien;
GRANT SELECT ON TABLE geoscrub_input TO bien_read;


--
-- Name: geoscrub_input_new; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE geoscrub_input_new FROM PUBLIC;
REVOKE ALL ON TABLE geoscrub_input_new FROM bien;
GRANT ALL ON TABLE geoscrub_input_new TO bien;
GRANT SELECT ON TABLE geoscrub_input_new TO bien_read;


--
-- Name: geoscrub_input_view; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE geoscrub_input_view FROM PUBLIC;
REVOKE ALL ON TABLE geoscrub_input_view FROM bien;
GRANT ALL ON TABLE geoscrub_input_view TO bien;
GRANT SELECT ON TABLE geoscrub_input_view TO bien_read;


--
-- Name: graphic; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE graphic FROM PUBLIC;
REVOKE ALL ON TABLE graphic FROM bien;
GRANT ALL ON TABLE graphic TO bien;
GRANT SELECT ON TABLE graphic TO bien_read;


--
-- Name: higher_plant_group_nodes; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE higher_plant_group_nodes FROM PUBLIC;
REVOKE ALL ON TABLE higher_plant_group_nodes FROM bien;
GRANT ALL ON TABLE higher_plant_group_nodes TO bien;
GRANT SELECT ON TABLE higher_plant_group_nodes TO bien_read;
GRANT SELECT ON TABLE higher_plant_group_nodes TO public_;


--
-- Name: locationeventcontributor; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE locationeventcontributor FROM PUBLIC;
REVOKE ALL ON TABLE locationeventcontributor FROM bien;
GRANT ALL ON TABLE locationeventcontributor TO bien;
GRANT SELECT ON TABLE locationeventcontributor TO bien_read;


--
-- Name: locationeventsynonym; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE locationeventsynonym FROM PUBLIC;
REVOKE ALL ON TABLE locationeventsynonym FROM bien;
GRANT ALL ON TABLE locationeventsynonym TO bien;
GRANT SELECT ON TABLE locationeventsynonym TO bien_read;


--
-- Name: methodtaxonclass; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE methodtaxonclass FROM PUBLIC;
REVOKE ALL ON TABLE methodtaxonclass FROM bien;
GRANT ALL ON TABLE methodtaxonclass TO bien;
GRANT SELECT ON TABLE methodtaxonclass TO bien_read;


--
-- Name: note; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE note FROM PUBLIC;
REVOKE ALL ON TABLE note FROM bien;
GRANT ALL ON TABLE note TO bien;
GRANT SELECT ON TABLE note TO bien_read;


--
-- Name: notelink; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE notelink FROM PUBLIC;
REVOKE ALL ON TABLE notelink FROM bien;
GRANT ALL ON TABLE notelink TO bien;
GRANT SELECT ON TABLE notelink TO bien_read;


--
-- Name: partymember; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE partymember FROM PUBLIC;
REVOKE ALL ON TABLE partymember FROM bien;
GRANT ALL ON TABLE partymember TO bien;
GRANT SELECT ON TABLE partymember TO bien_read;


--
-- Name: placecorrelation; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE placecorrelation FROM PUBLIC;
REVOKE ALL ON TABLE placecorrelation FROM bien;
GRANT ALL ON TABLE placecorrelation TO bien;
GRANT SELECT ON TABLE placecorrelation TO bien_read;


--
-- Name: placename; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE placename FROM PUBLIC;
REVOKE ALL ON TABLE placename FROM bien;
GRANT ALL ON TABLE placename TO bien;
GRANT SELECT ON TABLE placename TO bien_read;


--
-- Name: placename_ancestor; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE placename_ancestor FROM PUBLIC;
REVOKE ALL ON TABLE placename_ancestor FROM bien;
GRANT ALL ON TABLE placename_ancestor TO bien;
GRANT SELECT ON TABLE placename_ancestor TO bien_read;


--
-- Name: plant; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE plant FROM PUBLIC;
REVOKE ALL ON TABLE plant FROM bien;
GRANT ALL ON TABLE plant TO bien;
GRANT SELECT ON TABLE plant TO bien_read;


--
-- Name: plot.**; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE "plot.**" FROM PUBLIC;
REVOKE ALL ON TABLE "plot.**" FROM bien;
GRANT ALL ON TABLE "plot.**" TO bien;
GRANT SELECT ON TABLE "plot.**" TO bien_read;


--
-- Name: projectcontributor; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE projectcontributor FROM PUBLIC;
REVOKE ALL ON TABLE projectcontributor FROM bien;
GRANT ALL ON TABLE projectcontributor TO bien;
GRANT SELECT ON TABLE projectcontributor TO bien_read;


--
-- Name: provider_count; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE provider_count FROM PUBLIC;
REVOKE ALL ON TABLE provider_count FROM bien;
GRANT ALL ON TABLE provider_count TO bien;
GRANT SELECT ON TABLE provider_count TO bien_read;
GRANT SELECT ON TABLE provider_count TO public_;


--
-- Name: sourcename; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE sourcename FROM PUBLIC;
REVOKE ALL ON TABLE sourcename FROM bien;
GRANT ALL ON TABLE sourcename TO bien;
GRANT SELECT ON TABLE sourcename TO bien_read;
GRANT SELECT ON TABLE sourcename TO public_;


--
-- Name: provider_count_view; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE provider_count_view FROM PUBLIC;
REVOKE ALL ON TABLE provider_count_view FROM bien;
GRANT ALL ON TABLE provider_count_view TO bien;
GRANT SELECT ON TABLE provider_count_view TO bien_read;
GRANT SELECT ON TABLE provider_count_view TO public_;


--
-- Name: range_modeling_input; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE range_modeling_input FROM PUBLIC;
REVOKE ALL ON TABLE range_modeling_input FROM bien;
GRANT ALL ON TABLE range_modeling_input TO bien;
GRANT SELECT ON TABLE range_modeling_input TO bien_read;


--
-- Name: revision; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE revision FROM PUBLIC;
REVOKE ALL ON TABLE revision FROM bien;
GRANT ALL ON TABLE revision TO bien;
GRANT SELECT ON TABLE revision TO bien_read;


--
-- Name: soilsample; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE soilsample FROM PUBLIC;
REVOKE ALL ON TABLE soilsample FROM bien;
GRANT ALL ON TABLE soilsample TO bien;
GRANT SELECT ON TABLE soilsample TO bien_read;


--
-- Name: soiltaxon; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE soiltaxon FROM PUBLIC;
REVOKE ALL ON TABLE soiltaxon FROM bien;
GRANT ALL ON TABLE soiltaxon TO bien;
GRANT SELECT ON TABLE soiltaxon TO bien_read;


--
-- Name: sourcecontributor; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE sourcecontributor FROM PUBLIC;
REVOKE ALL ON TABLE sourcecontributor FROM bien;
GRANT ALL ON TABLE sourcecontributor TO bien;
GRANT SELECT ON TABLE sourcecontributor TO bien_read;


--
-- Name: specimen; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE specimen FROM PUBLIC;
REVOKE ALL ON TABLE specimen FROM bien;
GRANT ALL ON TABLE specimen TO bien;
GRANT SELECT ON TABLE specimen TO bien_read;


--
-- Name: taxon_trait; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxon_trait FROM PUBLIC;
REVOKE ALL ON TABLE taxon_trait FROM bien;
GRANT ALL ON TABLE taxon_trait TO bien;
GRANT SELECT ON TABLE taxon_trait TO bien_read;


--
-- Name: trait; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE trait FROM PUBLIC;
REVOKE ALL ON TABLE trait FROM bien;
GRANT ALL ON TABLE trait TO bien;
GRANT SELECT ON TABLE trait TO bien_read;


--
-- Name: taxon_trait_view; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxon_trait_view FROM PUBLIC;
REVOKE ALL ON TABLE taxon_trait_view FROM bien;
GRANT ALL ON TABLE taxon_trait_view TO bien;
GRANT SELECT ON TABLE taxon_trait_view TO bien_read;


--
-- Name: taxonalt; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonalt FROM PUBLIC;
REVOKE ALL ON TABLE taxonalt FROM bien;
GRANT ALL ON TABLE taxonalt TO bien;
GRANT SELECT ON TABLE taxonalt TO bien_read;


--
-- Name: taxonconcept; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonconcept FROM PUBLIC;
REVOKE ALL ON TABLE taxonconcept FROM bien;
GRANT ALL ON TABLE taxonconcept TO bien;
GRANT SELECT ON TABLE taxonconcept TO bien_read;


--
-- Name: taxoncorrelation; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxoncorrelation FROM PUBLIC;
REVOKE ALL ON TABLE taxoncorrelation FROM bien;
GRANT ALL ON TABLE taxoncorrelation TO bien;
GRANT SELECT ON TABLE taxoncorrelation TO bien_read;


--
-- Name: taxonlabel_relationship; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonlabel_relationship FROM PUBLIC;
REVOKE ALL ON TABLE taxonlabel_relationship FROM bien;
GRANT ALL ON TABLE taxonlabel_relationship TO bien;
GRANT SELECT ON TABLE taxonlabel_relationship TO bien_read;


--
-- Name: taxonlineage; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonlineage FROM PUBLIC;
REVOKE ALL ON TABLE taxonlineage FROM bien;
GRANT ALL ON TABLE taxonlineage TO bien;
GRANT SELECT ON TABLE taxonlineage TO bien_read;


--
-- Name: taxonstatus; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE taxonstatus FROM PUBLIC;
REVOKE ALL ON TABLE taxonstatus FROM bien;
GRANT ALL ON TABLE taxonstatus TO bien;
GRANT SELECT ON TABLE taxonstatus TO bien_read;


--
-- Name: telephone; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE telephone FROM PUBLIC;
REVOKE ALL ON TABLE telephone FROM bien;
GRANT ALL ON TABLE telephone TO bien;
GRANT SELECT ON TABLE telephone TO bien_read;


--
-- Name: threatened_taxonlabel_view; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE threatened_taxonlabel_view FROM PUBLIC;
REVOKE ALL ON TABLE threatened_taxonlabel_view FROM bien;
GRANT ALL ON TABLE threatened_taxonlabel_view TO bien;
GRANT SELECT ON TABLE threatened_taxonlabel_view TO bien_read;


--
-- Name: tnrs_input_name; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE tnrs_input_name FROM PUBLIC;
REVOKE ALL ON TABLE tnrs_input_name FROM bien;
GRANT ALL ON TABLE tnrs_input_name TO bien;
GRANT SELECT ON TABLE tnrs_input_name TO bien_read;


--
-- Name: userdefined; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE userdefined FROM PUBLIC;
REVOKE ALL ON TABLE userdefined FROM bien;
GRANT ALL ON TABLE userdefined TO bien;
GRANT SELECT ON TABLE userdefined TO bien_read;


--
-- Name: voucher; Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON TABLE voucher FROM PUBLIC;
REVOKE ALL ON TABLE voucher FROM bien;
GRANT ALL ON TABLE voucher TO bien;
GRANT SELECT ON TABLE voucher TO bien_read;


--
-- PostgreSQL database dump complete
--

