Project

General

Profile

1
CREATE TABLE tnrs
2
(
3
  "Time_submitted" timestamp with time zone,
4
  "Name_number" text,
5
  "Name_submitted" text NOT NULL,
6
  "Overall_score" text,
7
  "Name_matched" text,
8
  "Name_matched_rank" text,
9
  "Name_score" text,
10
  "Name_matched_author" text,
11
  "Name_matched_url" text,
12
  "Author_matched" text,
13
  "Author_score" text,
14
  "Family_matched" text,
15
  "Family_score" text,
16
  "Name_matched_accepted_family" text,
17
  "Genus_matched" text,
18
  "Genus_score" text,
19
  "Specific_epithet_matched" text,
20
  "Specific_epithet_score" text,
21
  "Infraspecific_rank" text,
22
  "Infraspecific_epithet_matched" text,
23
  "Infraspecific_epithet_score" text,
24
  "Infraspecific_rank_2" text,
25
  "Infraspecific_epithet_2_matched" text,
26
  "Infraspecific_epithet_2_score" text,
27
  "Annotations" text,
28
  "Unmatched_terms" text,
29
  "Taxonomic_status" text,
30
  "Accepted_name" text,
31
  "Accepted_name_author" text,
32
  "Accepted_name_rank" text,
33
  "Accepted_name_url" text,
34
  "Accepted_name_species" text,
35
  "Accepted_name_family" text,
36
  "Selected" text,
37
  "Source" text,
38
  "Warnings" text,
39
  "Accepted_name_lsid" text,
40
  "Accepted_scientific_name" text,
41
  CONSTRAINT tnrs_pkey PRIMARY KEY ("Name_submitted" )
42
)
43
WITH (
44
  OIDS=FALSE
45
);
46

    
47
CREATE OR REPLACE FUNCTION tnrs_populate_accepted_scientific_name()
48
  RETURNS trigger AS
49
$BODY$
50
BEGIN
51
    new."Accepted_scientific_name" = NULLIF(array_to_string(ARRAY[
52
        NULLIF(NULLIF(new."Accepted_name_family", 'Unknown'), new."Accepted_name")
53
        , new."Accepted_name"
54
        , new."Accepted_name_author"
55
    ], ' '), '');
56
    
57
    RETURN new;
58
END;
59
$BODY$
60
  LANGUAGE plpgsql VOLATILE
61
  COST 100;
62

    
63
CREATE TRIGGER tnrs_populate_accepted_scientific_name
64
  BEFORE INSERT OR UPDATE
65
  ON tnrs
66
  FOR EACH ROW
67
  EXECUTE PROCEDURE tnrs_populate_accepted_scientific_name();
(3-3/3)