Project

General

Profile

« Previous | Next » 

Revision 5548

schemas/vegbien.sql: taxonconcept: Rewrote taxonconcept() trigger to avoid completely reinserting the taxonconcept_ancestor entries of all descendants every time taxonconcept changes or using trigger recursion to find descendants. Instead, just delete the old parent's ancestors from and add the new parent's ancestors to each descendant, using taxonconcept_ancestor itself (with the new taxonconcept_ancestor_descendants index) to find all descendants. As an additional optimization, only update taxonconcept_ancestor if the parent_id or matched_concept_id has actually changed. This fixes a bug in NCBI where inserting taxonconcepts out of dependency order caused taxonconcept_ancestor entries to be repeatedly regenerated, slowing the import down to a crawl.

View differences:

schemas/vegbien.my.sql
186 186

  
187 187

  
188 188

  
189

  
190

  
191

  
192

  
189 193
--
190
-- Name: taxonconcept_update_ancestors(); Type: FUNCTION; Schema: public; Owner: -
194
-- Name: taxonconcept; Type: TABLE; Schema: public; Owner: -; Tablespace: 
191 195
--
192 196

  
197
CREATE TABLE taxonconcept (
198
    taxonconcept_id int(11) NOT NULL,
199
    creator_id int(11) NOT NULL,
200
    sourceaccessioncode text,
201
    creationdate date,
202
    accepted_concept_id int(11),
203
    matched_concept_id int(11),
204
    matched_concept_fit_fraction double precision,
205
    parent_id int(11),
206
    taxonname text,
207
    rank text,
208
    verbatimrank text,
209
    identifyingtaxonomicname text,
210
    taxonomicname text,
211
    author text,
212
    taxonomicnamewithauthor text,
213
    family text,
214
    genus text,
215
    species text,
216
    description text,
217
    accessioncode text
218
);
193 219

  
194 220

  
221
--
222
-- Name: TABLE taxonconcept; Type: COMMENT; Schema: public; Owner: -
223
--
195 224

  
225

  
226

  
227

  
196 228
--
197
-- Name: concat(text); Type: AGGREGATE; Schema: public; Owner: -
229
-- Name: COLUMN taxonconcept.creator_id; Type: COMMENT; Schema: public; Owner: -
198 230
--
199 231

  
200 232

  
201 233

  
202 234

  
235
--
236
-- Name: COLUMN taxonconcept.sourceaccessioncode; Type: COMMENT; Schema: public; Owner: -
237
--
203 238

  
204 239

  
205 240

  
206 241

  
207 242
--
243
-- Name: COLUMN taxonconcept.creationdate; Type: COMMENT; Schema: public; Owner: -
244
--
245

  
246

  
247

  
248

  
249
--
250
-- Name: COLUMN taxonconcept.accepted_concept_id; Type: COMMENT; Schema: public; Owner: -
251
--
252

  
253

  
254

  
255

  
256
--
257
-- Name: COLUMN taxonconcept.matched_concept_id; Type: COMMENT; Schema: public; Owner: -
258
--
259

  
260

  
261

  
262

  
263
--
264
-- Name: COLUMN taxonconcept.matched_concept_fit_fraction; Type: COMMENT; Schema: public; Owner: -
265
--
266

  
267

  
268

  
269

  
270
--
271
-- Name: COLUMN taxonconcept.parent_id; Type: COMMENT; Schema: public; Owner: -
272
--
273

  
274

  
275

  
276

  
277
--
278
-- Name: COLUMN taxonconcept.taxonname; Type: COMMENT; Schema: public; Owner: -
279
--
280

  
281

  
282

  
283

  
284
--
285
-- Name: COLUMN taxonconcept.rank; Type: COMMENT; Schema: public; Owner: -
286
--
287

  
288

  
289

  
290

  
291
--
292
-- Name: COLUMN taxonconcept.verbatimrank; Type: COMMENT; Schema: public; Owner: -
293
--
294

  
295

  
296

  
297

  
298
--
299
-- Name: COLUMN taxonconcept.identifyingtaxonomicname; Type: COMMENT; Schema: public; Owner: -
300
--
301

  
302

  
303

  
304

  
305
--
306
-- Name: COLUMN taxonconcept.taxonomicname; Type: COMMENT; Schema: public; Owner: -
307
--
308

  
309

  
310

  
311

  
312
--
313
-- Name: COLUMN taxonconcept.author; Type: COMMENT; Schema: public; Owner: -
314
--
315

  
316

  
317

  
318

  
319
--
320
-- Name: COLUMN taxonconcept.taxonomicnamewithauthor; Type: COMMENT; Schema: public; Owner: -
321
--
322

  
323

  
324

  
325

  
326
--
327
-- Name: COLUMN taxonconcept.family; Type: COMMENT; Schema: public; Owner: -
328
--
329

  
330

  
331

  
332

  
333
--
334
-- Name: COLUMN taxonconcept.genus; Type: COMMENT; Schema: public; Owner: -
335
--
336

  
337

  
338

  
339

  
340
--
341
-- Name: COLUMN taxonconcept.species; Type: COMMENT; Schema: public; Owner: -
342
--
343

  
344

  
345

  
346

  
347
--
348
-- Name: taxonconcept_update_ancestors(taxonconcept, int(11)); Type: FUNCTION; Schema: public; Owner: -
349
--
350

  
351

  
352

  
353

  
354
--
355
-- Name: taxonconcept_update_ancestors_on_insert(); Type: FUNCTION; Schema: public; Owner: -
356
--
357

  
358

  
359

  
360

  
361
--
362
-- Name: taxonconcept_update_ancestors_on_update(); Type: FUNCTION; Schema: public; Owner: -
363
--
364

  
365

  
366

  
367

  
368
--
369
-- Name: concat(text); Type: AGGREGATE; Schema: public; Owner: -
370
--
371

  
372

  
373

  
374

  
375
--
208 376
-- Name: address; Type: TABLE; Schema: public; Owner: -; Tablespace: 
209 377
--
210 378

  
......
810 978

  
811 979

  
812 980
--
813
-- Name: taxonconcept; Type: TABLE; Schema: public; Owner: -; Tablespace: 
814
--
815

  
816
CREATE TABLE taxonconcept (
817
    taxonconcept_id int(11) NOT NULL,
818
    creator_id int(11) NOT NULL,
819
    sourceaccessioncode text,
820
    creationdate date,
821
    accepted_concept_id int(11),
822
    matched_concept_id int(11),
823
    matched_concept_fit_fraction double precision,
824
    parent_id int(11),
825
    taxonname text,
826
    rank text,
827
    verbatimrank text,
828
    identifyingtaxonomicname text,
829
    taxonomicname text,
830
    author text,
831
    taxonomicnamewithauthor text,
832
    family text,
833
    genus text,
834
    species text,
835
    description text,
836
    accessioncode text
837
);
838

  
839

  
840
--
841
-- Name: TABLE taxonconcept; Type: COMMENT; Schema: public; Owner: -
842
--
843

  
844

  
845

  
846

  
847
--
848
-- Name: COLUMN taxonconcept.creator_id; Type: COMMENT; Schema: public; Owner: -
849
--
850

  
851

  
852

  
853

  
854
--
855
-- Name: COLUMN taxonconcept.sourceaccessioncode; Type: COMMENT; Schema: public; Owner: -
856
--
857

  
858

  
859

  
860

  
861
--
862
-- Name: COLUMN taxonconcept.creationdate; Type: COMMENT; Schema: public; Owner: -
863
--
864

  
865

  
866

  
867

  
868
--
869
-- Name: COLUMN taxonconcept.accepted_concept_id; Type: COMMENT; Schema: public; Owner: -
870
--
871

  
872

  
873

  
874

  
875
--
876
-- Name: COLUMN taxonconcept.matched_concept_id; Type: COMMENT; Schema: public; Owner: -
877
--
878

  
879

  
880

  
881

  
882
--
883
-- Name: COLUMN taxonconcept.matched_concept_fit_fraction; Type: COMMENT; Schema: public; Owner: -
884
--
885

  
886

  
887

  
888

  
889
--
890
-- Name: COLUMN taxonconcept.parent_id; Type: COMMENT; Schema: public; Owner: -
891
--
892

  
893

  
894

  
895

  
896
--
897
-- Name: COLUMN taxonconcept.taxonname; Type: COMMENT; Schema: public; Owner: -
898
--
899

  
900

  
901

  
902

  
903
--
904
-- Name: COLUMN taxonconcept.rank; Type: COMMENT; Schema: public; Owner: -
905
--
906

  
907

  
908

  
909

  
910
--
911
-- Name: COLUMN taxonconcept.verbatimrank; Type: COMMENT; Schema: public; Owner: -
912
--
913

  
914

  
915

  
916

  
917
--
918
-- Name: COLUMN taxonconcept.identifyingtaxonomicname; Type: COMMENT; Schema: public; Owner: -
919
--
920

  
921

  
922

  
923

  
924
--
925
-- Name: COLUMN taxonconcept.taxonomicname; Type: COMMENT; Schema: public; Owner: -
926
--
927

  
928

  
929

  
930

  
931
--
932
-- Name: COLUMN taxonconcept.author; Type: COMMENT; Schema: public; Owner: -
933
--
934

  
935

  
936

  
937

  
938
--
939
-- Name: COLUMN taxonconcept.taxonomicnamewithauthor; Type: COMMENT; Schema: public; Owner: -
940
--
941

  
942

  
943

  
944

  
945
--
946
-- Name: COLUMN taxonconcept.family; Type: COMMENT; Schema: public; Owner: -
947
--
948

  
949

  
950

  
951

  
952
--
953
-- Name: COLUMN taxonconcept.genus; Type: COMMENT; Schema: public; Owner: -
954
--
955

  
956

  
957

  
958

  
959
--
960
-- Name: COLUMN taxonconcept.species; Type: COMMENT; Schema: public; Owner: -
961
--
962

  
963

  
964

  
965

  
966
--
967 981
-- Name: taxondetermination; Type: TABLE; Schema: public; Owner: -; Tablespace: 
968 982
--
969 983

  
......
4125 4139

  
4126 4140

  
4127 4141
--
4128
-- Name: taxonconcept_update_ancestors; Type: TRIGGER; Schema: public; Owner: -
4142
-- Name: taxonconcept_update_ancestors_on_insert; Type: TRIGGER; Schema: public; Owner: -
4129 4143
--
4130 4144

  
4131 4145

  
4132 4146

  
4133 4147

  
4134 4148
--
4149
-- Name: taxonconcept_update_ancestors_on_update; Type: TRIGGER; Schema: public; Owner: -
4150
--
4151

  
4152

  
4153

  
4154

  
4155
--
4135 4156
-- Name: address_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4136 4157
--
4137 4158

  
schemas/vegbien.sql
485 485
$$;
486 486

  
487 487

  
488
SET default_tablespace = '';
489

  
490
SET default_with_oids = false;
491

  
488 492
--
489
-- Name: taxonconcept_update_ancestors(); Type: FUNCTION; Schema: public; Owner: -
493
-- Name: taxonconcept; Type: TABLE; Schema: public; Owner: -; Tablespace: 
490 494
--
491 495

  
492
CREATE FUNCTION taxonconcept_update_ancestors() RETURNS trigger
496
CREATE TABLE taxonconcept (
497
    taxonconcept_id integer NOT NULL,
498
    creator_id integer NOT NULL,
499
    sourceaccessioncode text,
500
    creationdate date,
501
    accepted_concept_id integer,
502
    matched_concept_id integer,
503
    matched_concept_fit_fraction double precision,
504
    parent_id integer,
505
    taxonname text,
506
    rank taxonrank,
507
    verbatimrank text,
508
    identifyingtaxonomicname text,
509
    taxonomicname text,
510
    author text,
511
    taxonomicnamewithauthor text,
512
    family text,
513
    genus text,
514
    species text,
515
    description text,
516
    accessioncode text,
517
    CONSTRAINT taxonconcept_matched_concept_fit_fraction_range CHECK (((matched_concept_fit_fraction >= (0)::double precision) AND (matched_concept_fit_fraction <= (1)::double precision))),
518
    CONSTRAINT taxonconcept_required_key CHECK (((((((sourceaccessioncode IS NOT NULL) OR (taxonname IS NOT NULL)) OR (identifyingtaxonomicname IS NOT NULL)) OR (taxonomicname IS NOT NULL)) OR (taxonomicnamewithauthor IS NOT NULL)) OR ((parent_id IS NOT NULL) AND ((creationdate IS NOT NULL) OR (author IS NOT NULL)))))
519
);
520

  
521

  
522
--
523
-- Name: TABLE taxonconcept; Type: COMMENT; Schema: public; Owner: -
524
--
525

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

  
528
"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)
529

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

  
532
To include a taxon name at a rank with no explicit column, create a parent taxonconcept for it and point to it using parent_id. To include multiple such names, chain the taxonconcepts together using parent_id. Note that lower-level taxa should point to higher-level taxa.
533

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

  
536

  
537
--
538
-- Name: COLUMN taxonconcept.creator_id; Type: COMMENT; Schema: public; Owner: -
539
--
540

  
541
COMMENT ON COLUMN taxonconcept.creator_id IS 'The entity that created the taxon concept.';
542

  
543

  
544
--
545
-- Name: COLUMN taxonconcept.sourceaccessioncode; Type: COMMENT; Schema: public; Owner: -
546
--
547

  
548
COMMENT ON COLUMN taxonconcept.sourceaccessioncode IS 'The datasource''s identifier for the taxonconcept.';
549

  
550

  
551
--
552
-- Name: COLUMN taxonconcept.creationdate; Type: COMMENT; Schema: public; Owner: -
553
--
554

  
555
COMMENT ON COLUMN taxonconcept.creationdate IS 'The date the taxonconcept was created or defined. For a taxonconcept applied in a taxondetermination, this is the date the determination was made.';
556

  
557

  
558
--
559
-- Name: COLUMN taxonconcept.accepted_concept_id; Type: COMMENT; Schema: public; Owner: -
560
--
561

  
562
COMMENT ON COLUMN taxonconcept.accepted_concept_id IS 'The accepted synonym of the taxonconcept.';
563

  
564

  
565
--
566
-- Name: COLUMN taxonconcept.matched_concept_id; Type: COMMENT; Schema: public; Owner: -
567
--
568

  
569
COMMENT ON COLUMN taxonconcept.matched_concept_id IS 'The taxonconcept containing the closest match to this taxonconcept. taxonconcepts should be linked in a four-level hierarchy of datasource concept -> parsed concept -> matched concept -> accepted concept. A previously-accepted name''s concept should be further linked to the synonym that has replaced it.
570

  
571
To indicate a synonym between taxonconcepts of different sources, choose one taxonconcept to be authoritative and point the other taxonconcept to it using this field.
572

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

  
575

  
576
--
577
-- Name: COLUMN taxonconcept.matched_concept_fit_fraction; Type: COMMENT; Schema: public; Owner: -
578
--
579

  
580
COMMENT ON COLUMN taxonconcept.matched_concept_fit_fraction IS 'The closeness of fit of the matched_concept.';
581

  
582

  
583
--
584
-- Name: COLUMN taxonconcept.parent_id; Type: COMMENT; Schema: public; Owner: -
585
--
586

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

  
589

  
590
--
591
-- Name: COLUMN taxonconcept.taxonname; Type: COMMENT; Schema: public; Owner: -
592
--
593

  
594
COMMENT ON COLUMN taxonconcept.taxonname IS 'The name of the taxon within its parent taxon. This is the lowest-rank portion of this taxonconcept''s full taxonomic name, if it has one.
595

  
596
The morphospecies suffix goes in this field.';
597

  
598

  
599
--
600
-- Name: COLUMN taxonconcept.rank; Type: COMMENT; Schema: public; Owner: -
601
--
602

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

  
605

  
606
--
607
-- Name: COLUMN taxonconcept.verbatimrank; Type: COMMENT; Schema: public; Owner: -
608
--
609

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

  
612

  
613
--
614
-- Name: COLUMN taxonconcept.identifyingtaxonomicname; Type: COMMENT; Schema: public; Owner: -
615
--
616

  
617
COMMENT ON COLUMN taxonconcept.identifyingtaxonomicname IS 'The taxonomic name that uniquely identifies this taxonconcept. If set, the other fields will not be used in duplicate elimination.';
618

  
619

  
620
--
621
-- Name: COLUMN taxonconcept.taxonomicname; Type: COMMENT; Schema: public; Owner: -
622
--
623

  
624
COMMENT ON COLUMN taxonconcept.taxonomicname IS 'The concatenated taxonomic name which uniquely identifies this taxon. Does not include the author of the name.
625

  
626
Equivalent to Darwin Core''s scientificName.';
627

  
628

  
629
--
630
-- Name: COLUMN taxonconcept.author; Type: COMMENT; Schema: public; Owner: -
631
--
632

  
633
COMMENT ON COLUMN taxonconcept.author IS 'The author of the taxonomic name.
634

  
635
Equivalent to Darwin Core''s scientificNameAuthorship.';
636

  
637

  
638
--
639
-- Name: COLUMN taxonconcept.taxonomicnamewithauthor; Type: COMMENT; Schema: public; Owner: -
640
--
641

  
642
COMMENT ON COLUMN taxonconcept.taxonomicnamewithauthor IS 'The concatenated taxonomic name which uniquely identifies this taxon, plus the author of that name.
643

  
644
Equivalent to Darwin Core''s scientificName + scientificNameAuthorship.
645
Equivalent to "Name sec. x".';
646

  
647

  
648
--
649
-- Name: COLUMN taxonconcept.family; Type: COMMENT; Schema: public; Owner: -
650
--
651

  
652
COMMENT ON COLUMN taxonconcept.family IS 'The family of the taxonomic name. This is a cached field for easy querying; the identifying version of this field is stored in the chain of parent_id ancestors.';
653

  
654

  
655
--
656
-- Name: COLUMN taxonconcept.genus; Type: COMMENT; Schema: public; Owner: -
657
--
658

  
659
COMMENT ON COLUMN taxonconcept.genus IS 'The genus portion of the taxonomic name. This is a cached field for easy querying; the identifying version of this field is stored in the chain of parent_id ancestors.';
660

  
661

  
662
--
663
-- Name: COLUMN taxonconcept.species; Type: COMMENT; Schema: public; Owner: -
664
--
665

  
666
COMMENT ON COLUMN taxonconcept.species IS 'The species portion of the taxonomic name. This is a cached field for easy querying; the identifying version of this field is stored in the chain of parent_id ancestors.';
667

  
668

  
669
--
670
-- Name: taxonconcept_update_ancestors(taxonconcept, integer); Type: FUNCTION; Schema: public; Owner: -
671
--
672

  
673
CREATE FUNCTION taxonconcept_update_ancestors(new taxonconcept, old_parent_id integer DEFAULT NULL::integer) RETURNS void
493 674
    LANGUAGE plpgsql
494 675
    AS $$
495 676
DECLARE
......
497 678
    parent_id_ taxonconcept.taxonconcept_id%TYPE :=
498 679
        COALESCE(new.matched_concept_id, new.parent_id);
499 680
BEGIN
500
    -- Delete existing ancestors
501
    DELETE FROM taxonconcept_ancestor
502
    WHERE taxonconcept_id = new.taxonconcept_id;
503
    
504
    IF parent_id_ IS NOT NULL THEN
505
        -- Copy parent's ancestors to this node's ancestors
506
        INSERT
507
        INTO taxonconcept_ancestor
508
        (taxonconcept_id, ancestor_id)
509
        SELECT
510
            new.taxonconcept_id, ancestor_id
511
        FROM taxonconcept_ancestor
512
        WHERE taxonconcept_id = parent_id_
513
        ;
681
    IF parent_id_ IS DISTINCT FROM old_parent_id THEN
682
        DECLARE
683
            -- These include the parent itself
684
            old_ancestors integer[] := (
685
                SELECT array_agg(ancestor_id) FROM taxonconcept_ancestor
686
                WHERE taxonconcept_id = old_parent_id
687
            );
688
            new_ancestors integer[] := (
689
                SELECT array_agg(ancestor_id) FROM taxonconcept_ancestor
690
                WHERE taxonconcept_id = parent_id_
691
            );
692
            descendant_id integer;
693
        BEGIN
694
            FOR descendant_id IN -- also includes self
695
                SELECT taxonconcept_id
696
                FROM taxonconcept_ancestor
697
                WHERE ancestor_id = new.taxonconcept_id
698
            LOOP
699
                -- Delete old parent's ancestors
700
                DELETE FROM taxonconcept_ancestor
701
                WHERE taxonconcept_id = descendant_id
702
                AND ancestor_id = ANY (old_ancestors)
703
                ;
704
                
705
                -- Add new parent's ancestors
706
                INSERT INTO taxonconcept_ancestor
707
                (taxonconcept_id, ancestor_id)
708
                SELECT descendant_id, unnest(new_ancestors)
709
                ;
710
            END LOOP;
711
        END;
514 712
    END IF;
515 713
    
516
    -- Add "ancestor" for this node
517
    /* This is useful for queries, because you don't have to separately test if
518
    the leaf node is the one you're looking for, in addition to that leaf node's
519
    ancestors. */
714
    /* Note: We don't need an ON DELETE trigger to update the descendants'
715
    ancestors when a node is deleted, because the taxonconcept.parent_id foreign
716
    key is ON DELETE CASCADE, which just removes all the descendants anyway. */
717
END;
718
$$;
719

  
720

  
721
--
722
-- Name: taxonconcept_update_ancestors_on_insert(); Type: FUNCTION; Schema: public; Owner: -
723
--
724

  
725
CREATE FUNCTION taxonconcept_update_ancestors_on_insert() RETURNS trigger
726
    LANGUAGE plpgsql
727
    AS $$
728
BEGIN
729
    /* Add "ancestor" for this node. This is useful for queries, because you
730
    don't have to separately test if the leaf node is the one you're looking
731
    for, in addition to that leaf node's ancestors. */
520 732
    INSERT
521 733
    INTO taxonconcept_ancestor
522 734
    (taxonconcept_id, ancestor_id)
523 735
    VALUES (new.taxonconcept_id, new.taxonconcept_id)
524 736
    ;
525 737
    
526
    -- Tell immediate children to update their ancestors lists, which will
527
    -- recursively tell all descendants
528
    UPDATE taxonconcept
529
    SET taxonconcept_id = taxonconcept_id -- need at least one SET statement
530
    -- Add COALESCE() to enable using taxonconcept_unique index for lookup
531
    WHERE COALESCE(parent_id, 2147483647) = new.taxonconcept_id
532
    AND taxonconcept_id != new.taxonconcept_id -- avoid infinite recursion
533
    ;
738
    PERFORM taxonconcept_update_ancestors(new);
534 739
    
535
    /* Note: We don't need an ON DELETE trigger to update the descendants'
536
    ancestors when a node is deleted, because the taxonconcept.parent_id foreign
537
    key is ON DELETE CASCADE, which just removes all the descendants anyway. */
740
    RETURN new;
741
END;
742
$$;
743

  
744

  
745
--
746
-- Name: taxonconcept_update_ancestors_on_update(); Type: FUNCTION; Schema: public; Owner: -
747
--
748

  
749
CREATE FUNCTION taxonconcept_update_ancestors_on_update() RETURNS trigger
750
    LANGUAGE plpgsql
751
    AS $$
752
BEGIN
753
    PERFORM taxonconcept_update_ancestors(new,
754
        COALESCE(old.matched_concept_id, old.parent_id));
538 755
    
539 756
    RETURN new;
540 757
END;
......
552 769
);
553 770

  
554 771

  
555
SET default_tablespace = '';
556

  
557
SET default_with_oids = false;
558

  
559 772
--
560 773
-- Name: address; Type: TABLE; Schema: public; Owner: -; Tablespace: 
561 774
--
......
1204 1417

  
1205 1418

  
1206 1419
--
1207
-- Name: taxonconcept; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1208
--
1209

  
1210
CREATE TABLE taxonconcept (
1211
    taxonconcept_id integer NOT NULL,
1212
    creator_id integer NOT NULL,
1213
    sourceaccessioncode text,
1214
    creationdate date,
1215
    accepted_concept_id integer,
1216
    matched_concept_id integer,
1217
    matched_concept_fit_fraction double precision,
1218
    parent_id integer,
1219
    taxonname text,
1220
    rank taxonrank,
1221
    verbatimrank text,
1222
    identifyingtaxonomicname text,
1223
    taxonomicname text,
1224
    author text,
1225
    taxonomicnamewithauthor text,
1226
    family text,
1227
    genus text,
1228
    species text,
1229
    description text,
1230
    accessioncode text,
1231
    CONSTRAINT taxonconcept_matched_concept_fit_fraction_range CHECK (((matched_concept_fit_fraction >= (0)::double precision) AND (matched_concept_fit_fraction <= (1)::double precision))),
1232
    CONSTRAINT taxonconcept_required_key CHECK (((((((sourceaccessioncode IS NOT NULL) OR (taxonname IS NOT NULL)) OR (identifyingtaxonomicname IS NOT NULL)) OR (taxonomicname IS NOT NULL)) OR (taxonomicnamewithauthor IS NOT NULL)) OR ((parent_id IS NOT NULL) AND ((creationdate IS NOT NULL) OR (author IS NOT NULL)))))
1233
);
1234

  
1235

  
1236
--
1237
-- Name: TABLE taxonconcept; Type: COMMENT; Schema: public; Owner: -
1238
--
1239

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

  
1242
"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)
1243

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

  
1246
To include a taxon name at a rank with no explicit column, create a parent taxonconcept for it and point to it using parent_id. To include multiple such names, chain the taxonconcepts together using parent_id. Note that lower-level taxa should point to higher-level taxa.
1247

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

  
1250

  
1251
--
1252
-- Name: COLUMN taxonconcept.creator_id; Type: COMMENT; Schema: public; Owner: -
1253
--
1254

  
1255
COMMENT ON COLUMN taxonconcept.creator_id IS 'The entity that created the taxon concept.';
1256

  
1257

  
1258
--
1259
-- Name: COLUMN taxonconcept.sourceaccessioncode; Type: COMMENT; Schema: public; Owner: -
1260
--
1261

  
1262
COMMENT ON COLUMN taxonconcept.sourceaccessioncode IS 'The datasource''s identifier for the taxonconcept.';
1263

  
1264

  
1265
--
1266
-- Name: COLUMN taxonconcept.creationdate; Type: COMMENT; Schema: public; Owner: -
1267
--
1268

  
1269
COMMENT ON COLUMN taxonconcept.creationdate IS 'The date the taxonconcept was created or defined. For a taxonconcept applied in a taxondetermination, this is the date the determination was made.';
1270

  
1271

  
1272
--
1273
-- Name: COLUMN taxonconcept.accepted_concept_id; Type: COMMENT; Schema: public; Owner: -
1274
--
1275

  
1276
COMMENT ON COLUMN taxonconcept.accepted_concept_id IS 'The accepted synonym of the taxonconcept.';
1277

  
1278

  
1279
--
1280
-- Name: COLUMN taxonconcept.matched_concept_id; Type: COMMENT; Schema: public; Owner: -
1281
--
1282

  
1283
COMMENT ON COLUMN taxonconcept.matched_concept_id IS 'The taxonconcept containing the closest match to this taxonconcept. taxonconcepts should be linked in a four-level hierarchy of datasource concept -> parsed concept -> matched concept -> accepted concept. A previously-accepted name''s concept should be further linked to the synonym that has replaced it.
1284

  
1285
To indicate a synonym between taxonconcepts of different sources, choose one taxonconcept to be authoritative and point the other taxonconcept to it using this field.
1286

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

  
1289

  
1290
--
1291
-- Name: COLUMN taxonconcept.matched_concept_fit_fraction; Type: COMMENT; Schema: public; Owner: -
1292
--
1293

  
1294
COMMENT ON COLUMN taxonconcept.matched_concept_fit_fraction IS 'The closeness of fit of the matched_concept.';
1295

  
1296

  
1297
--
1298
-- Name: COLUMN taxonconcept.parent_id; Type: COMMENT; Schema: public; Owner: -
1299
--
1300

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

  
1303

  
1304
--
1305
-- Name: COLUMN taxonconcept.taxonname; Type: COMMENT; Schema: public; Owner: -
1306
--
1307

  
1308
COMMENT ON COLUMN taxonconcept.taxonname IS 'The name of the taxon within its parent taxon. This is the lowest-rank portion of this taxonconcept''s full taxonomic name, if it has one.
1309

  
1310
The morphospecies suffix goes in this field.';
1311

  
1312

  
1313
--
1314
-- Name: COLUMN taxonconcept.rank; Type: COMMENT; Schema: public; Owner: -
1315
--
1316

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

  
1319

  
1320
--
1321
-- Name: COLUMN taxonconcept.verbatimrank; Type: COMMENT; Schema: public; Owner: -
1322
--
1323

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

  
1326

  
1327
--
1328
-- Name: COLUMN taxonconcept.identifyingtaxonomicname; Type: COMMENT; Schema: public; Owner: -
1329
--
1330

  
1331
COMMENT ON COLUMN taxonconcept.identifyingtaxonomicname IS 'The taxonomic name that uniquely identifies this taxonconcept. If set, the other fields will not be used in duplicate elimination.';
1332

  
1333

  
1334
--
1335
-- Name: COLUMN taxonconcept.taxonomicname; Type: COMMENT; Schema: public; Owner: -
1336
--
1337

  
1338
COMMENT ON COLUMN taxonconcept.taxonomicname IS 'The concatenated taxonomic name which uniquely identifies this taxon. Does not include the author of the name.
1339

  
1340
Equivalent to Darwin Core''s scientificName.';
1341

  
1342

  
1343
--
1344
-- Name: COLUMN taxonconcept.author; Type: COMMENT; Schema: public; Owner: -
1345
--
1346

  
1347
COMMENT ON COLUMN taxonconcept.author IS 'The author of the taxonomic name.
1348

  
1349
Equivalent to Darwin Core''s scientificNameAuthorship.';
1350

  
1351

  
1352
--
1353
-- Name: COLUMN taxonconcept.taxonomicnamewithauthor; Type: COMMENT; Schema: public; Owner: -
1354
--
1355

  
1356
COMMENT ON COLUMN taxonconcept.taxonomicnamewithauthor IS 'The concatenated taxonomic name which uniquely identifies this taxon, plus the author of that name.
1357

  
1358
Equivalent to Darwin Core''s scientificName + scientificNameAuthorship.
1359
Equivalent to "Name sec. x".';
1360

  
1361

  
1362
--
1363
-- Name: COLUMN taxonconcept.family; Type: COMMENT; Schema: public; Owner: -
1364
--
1365

  
1366
COMMENT ON COLUMN taxonconcept.family IS 'The family of the taxonomic name. This is a cached field for easy querying; the identifying version of this field is stored in the chain of parent_id ancestors.';
1367

  
1368

  
1369
--
1370
-- Name: COLUMN taxonconcept.genus; Type: COMMENT; Schema: public; Owner: -
1371
--
1372

  
1373
COMMENT ON COLUMN taxonconcept.genus IS 'The genus portion of the taxonomic name. This is a cached field for easy querying; the identifying version of this field is stored in the chain of parent_id ancestors.';
1374

  
1375

  
1376
--
1377
-- Name: COLUMN taxonconcept.species; Type: COMMENT; Schema: public; Owner: -
1378
--
1379

  
1380
COMMENT ON COLUMN taxonconcept.species IS 'The species portion of the taxonomic name. This is a cached field for easy querying; the identifying version of this field is stored in the chain of parent_id ancestors.';
1381

  
1382

  
1383
--
1384 1420
-- Name: taxondetermination; Type: TABLE; Schema: public; Owner: -; Tablespace: 
1385 1421
--
1386 1422

  
......
4836 4872

  
4837 4873

  
4838 4874
--
4839
-- Name: taxonconcept_update_ancestors; Type: TRIGGER; Schema: public; Owner: -
4875
-- Name: taxonconcept_update_ancestors_on_insert; Type: TRIGGER; Schema: public; Owner: -
4840 4876
--
4841 4877

  
4842
CREATE CONSTRAINT TRIGGER taxonconcept_update_ancestors AFTER INSERT OR UPDATE ON taxonconcept DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE taxonconcept_update_ancestors();
4878
CREATE TRIGGER taxonconcept_update_ancestors_on_insert AFTER INSERT ON taxonconcept FOR EACH ROW EXECUTE PROCEDURE taxonconcept_update_ancestors_on_insert();
4843 4879

  
4844 4880

  
4845 4881
--
4882
-- Name: taxonconcept_update_ancestors_on_update; Type: TRIGGER; Schema: public; Owner: -
4883
--
4884

  
4885
CREATE TRIGGER taxonconcept_update_ancestors_on_update AFTER UPDATE ON taxonconcept FOR EACH ROW EXECUTE PROCEDURE taxonconcept_update_ancestors_on_update();
4886

  
4887

  
4888
--
4846 4889
-- Name: address_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4847 4890
--
4848 4891

  

Also available in: Unified diff