Project

General

Profile

« Previous | Next » 

Revision 5282

schemas/vegbien.sql: Removed no longer used taxon table. Use taxonconcept instead.

View differences:

vegbien.sql
377 377

  
378 378

  
379 379
--
380
-- Name: taxon_update_ancestors(); Type: FUNCTION; Schema: public; Owner: -
381
--
382

  
383
CREATE FUNCTION taxon_update_ancestors() RETURNS trigger
384
    LANGUAGE plpgsql
385
    AS $$
386
BEGIN
387
    -- Delete existing ancestors
388
    DELETE FROM taxon_ancestor WHERE taxon_id = new.taxon_id;
389
    
390
    IF new.parent_id IS NOT NULL THEN
391
        -- Copy parent's ancestors to this node's ancestors
392
        INSERT
393
        INTO taxon_ancestor
394
        (taxon_id, ancestor_id)
395
        SELECT
396
            new.taxon_id, ancestor_id
397
        FROM taxon_ancestor
398
        WHERE taxon_id = new.parent_id
399
        ;
400
    END IF;
401
    
402
    -- Add "ancestor" for this node
403
    /* This is useful for queries, because you don't have to separately test if
404
    the leaf node is the one you're looking for, in addition to that leaf node's
405
    ancestors. */
406
    INSERT
407
    INTO taxon_ancestor
408
    (taxon_id, ancestor_id)
409
    VALUES (new.taxon_id, new.taxon_id)
410
    ;
411
    
412
    -- Tell immediate children to update their ancestors lists, which will
413
    -- recursively tell all descendants
414
    UPDATE taxon
415
    SET taxon_id = taxon_id -- need at least one SET statement
416
    -- Add COALESCE() to enable using taxon_unique index for lookup
417
    WHERE COALESCE(parent_id, 2147483647) = new.taxon_id
418
    ;
419
    
420
    /* Note: We don't need an ON DELETE trigger to update the descendants'
421
    ancestors when a node is deleted, because the taxon.taxon_parent_id
422
    foreign key is set to ON DELETE CASCADE, which just removes all the
423
    descendants anyway. */
424
    
425
    RETURN new;
426
END;
427
$$;
428

  
429

  
430
--
431 380
-- Name: taxonconcept_canon_taxonconcept_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
432 381
--
433 382

  
......
3101 3050

  
3102 3051

  
3103 3052
--
3104
-- Name: taxon; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3105
--
3106

  
3107
CREATE TABLE taxon (
3108
    taxon_id integer NOT NULL,
3109
    parent_id integer,
3110
    rank taxonrank NOT NULL,
3111
    verbatimrank text,
3112
    taxonname text NOT NULL,
3113
    author_id integer,
3114
    authority_id integer,
3115
    description text,
3116
    accessioncode text
3117
);
3118

  
3119

  
3120
--
3121
-- Name: TABLE taxon; Type: COMMENT; Schema: public; Owner: -
3122
--
3123

  
3124
COMMENT ON TABLE taxon IS 'A formal, named taxon in the tree of life. Can be at any level in the taxonomic hierarchy. Note that the taxon name stores only one rank (e.g. family) of the full taxonomic name. The higher-level ranks are stored in the taxon''s chain of parent_id ancestors.
3125

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

  
3129

  
3130
--
3131
-- Name: COLUMN taxon.parent_id; Type: COMMENT; Schema: public; Owner: -
3132
--
3133

  
3134
COMMENT ON COLUMN taxon.parent_id IS 'The parent taxon.';
3135

  
3136

  
3137
--
3138
-- Name: COLUMN taxon.rank; Type: COMMENT; Schema: public; Owner: -
3139
--
3140

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

  
3143

  
3144
--
3145
-- Name: COLUMN taxon.verbatimrank; Type: COMMENT; Schema: public; Owner: -
3146
--
3147

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

  
3150

  
3151
--
3152
-- Name: COLUMN taxon.taxonname; Type: COMMENT; Schema: public; Owner: -
3153
--
3154

  
3155
COMMENT ON COLUMN taxon.taxonname IS 'The name of the taxon within its parent taxon. Contains only the lowest-rank portion of the taxonomic name. (The higher-level ranks are stored in the taxon''s chain of parent_id ancestors.)';
3156

  
3157

  
3158
--
3159
-- Name: COLUMN taxon.author_id; Type: COMMENT; Schema: public; Owner: -
3160
--
3161

  
3162
COMMENT ON COLUMN taxon.author_id IS 'The author of the taxon name.';
3163

  
3164

  
3165
--
3166
-- Name: COLUMN taxon.authority_id; Type: COMMENT; Schema: public; Owner: -
3167
--
3168

  
3169
COMMENT ON COLUMN taxon.authority_id IS 'The authority which defines the taxon name.';
3170

  
3171

  
3172
--
3173
-- Name: COLUMN taxon.description; Type: COMMENT; Schema: public; Owner: -
3174
--
3175

  
3176
COMMENT ON COLUMN taxon.description IS 'The authority''s description of the taxon.';
3177

  
3178

  
3179
--
3180
-- Name: taxon_ancestor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3181
--
3182

  
3183
CREATE TABLE taxon_ancestor (
3184
    taxon_id integer NOT NULL,
3185
    ancestor_id integer NOT NULL
3186
);
3187

  
3188

  
3189
--
3190
-- Name: taxon_taxon_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3191
--
3192

  
3193
CREATE SEQUENCE taxon_taxon_id_seq
3194
    START WITH 1
3195
    INCREMENT BY 1
3196
    NO MINVALUE
3197
    NO MAXVALUE
3198
    CACHE 1;
3199

  
3200

  
3201
--
3202
-- Name: taxon_taxon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3203
--
3204

  
3205
ALTER SEQUENCE taxon_taxon_id_seq OWNED BY taxon.taxon_id;
3206

  
3207

  
3208
--
3209 3053
-- Name: taxonalt; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3210 3054
--
3211 3055

  
......
3789 3633

  
3790 3634

  
3791 3635
--
3792
-- Name: taxon_id; Type: DEFAULT; Schema: public; Owner: -
3793
--
3794

  
3795
ALTER TABLE taxon ALTER COLUMN taxon_id SET DEFAULT nextval('taxon_taxon_id_seq'::regclass);
3796

  
3797

  
3798
--
3799 3636
-- Name: taxonalt_id; Type: DEFAULT; Schema: public; Owner: -
3800 3637
--
3801 3638

  
......
4340 4177

  
4341 4178

  
4342 4179
--
4343
-- Name: taxon_ancestor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4344
--
4345

  
4346
ALTER TABLE ONLY taxon_ancestor
4347
    ADD CONSTRAINT taxon_ancestor_pkey PRIMARY KEY (taxon_id, ancestor_id);
4348

  
4349

  
4350
--
4351
-- Name: taxon_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4352
--
4353

  
4354
ALTER TABLE ONLY taxon
4355
    ADD CONSTRAINT taxon_pkey PRIMARY KEY (taxon_id);
4356

  
4357

  
4358
--
4359 4180
-- Name: taxonalt_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4360 4181
--
4361 4182

  
......
4794 4615

  
4795 4616

  
4796 4617
--
4797
-- Name: taxon_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4798
--
4799

  
4800
CREATE UNIQUE INDEX taxon_unique ON taxon USING btree ((COALESCE(parent_id, 2147483647)), taxonname, rank, (COALESCE(author_id, 2147483647)), (COALESCE(authority_id, 2147483647)));
4801

  
4802

  
4803
--
4804 4618
-- Name: taxonconcept_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4805 4619
--
4806 4620

  
......
4906 4720

  
4907 4721

  
4908 4722
--
4909
-- Name: taxon_update_ancestors; Type: TRIGGER; Schema: public; Owner: -
4910
--
4911

  
4912
CREATE TRIGGER taxon_update_ancestors AFTER INSERT OR UPDATE ON taxon FOR EACH ROW EXECUTE PROCEDURE taxon_update_ancestors();
4913

  
4914

  
4915
--
4916 4723
-- Name: taxonconcept_canon_taxonconcept_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
4917 4724
--
4918 4725

  
......
5767 5574

  
5768 5575

  
5769 5576
--
5770
-- Name: taxon_ancestor_ancestor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5771
--
5772

  
5773
ALTER TABLE ONLY taxon_ancestor
5774
    ADD CONSTRAINT taxon_ancestor_ancestor_id_fkey FOREIGN KEY (ancestor_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5775

  
5776

  
5777
--
5778
-- Name: taxon_ancestor_taxon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5779
--
5780

  
5781
ALTER TABLE ONLY taxon_ancestor
5782
    ADD CONSTRAINT taxon_ancestor_taxon_id_fkey FOREIGN KEY (taxon_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5783

  
5784

  
5785
--
5786
-- Name: taxon_author_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5787
--
5788

  
5789
ALTER TABLE ONLY taxon
5790
    ADD CONSTRAINT taxon_author_id_fkey FOREIGN KEY (author_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5791

  
5792

  
5793
--
5794
-- Name: taxon_authority_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5795
--
5796

  
5797
ALTER TABLE ONLY taxon
5798
    ADD CONSTRAINT taxon_authority_id_fkey FOREIGN KEY (authority_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
5799

  
5800

  
5801
--
5802
-- Name: taxon_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5803
--
5804

  
5805
ALTER TABLE ONLY taxon
5806
    ADD CONSTRAINT taxon_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5807

  
5808

  
5809
--
5810 5577
-- Name: taxonalt_taxonconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5811 5578
--
5812 5579

  

Also available in: Unified diff