Project

General

Profile

1
CREATE OR REPLACE FUNCTION array_to_string(anyarray, text)
2
  RETURNS text AS
3
$BODY$
4
SELECT pg_catalog.array_to_string($1, $2)
5
$BODY$
6
  LANGUAGE sql IMMUTABLE STRICT
7
  COST 100;
8

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

    
55
CREATE OR REPLACE VIEW "tnrs+accepted" AS
56
SELECT
57
tnrs.*
58
, tnrs_accepted."Time_submitted"                  AS "Accepted_name.Time_submitted"
59
, tnrs_accepted."Name_number"                     AS "Accepted_name.Name_number"
60
, tnrs_accepted."Name_submitted"                  AS "Accepted_name.Name_submitted"
61
, tnrs_accepted."Overall_score"                   AS "Accepted_name.Overall_score"
62
, tnrs_accepted."Name_matched"                    AS "Accepted_name.Name_matched"
63
, tnrs_accepted."Name_matched_rank"               AS "Accepted_name.Name_matched_rank"
64
, tnrs_accepted."Name_score"                      AS "Accepted_name.Name_score"
65
, tnrs_accepted."Name_matched_author"             AS "Accepted_name.Name_matched_author"
66
, tnrs_accepted."Name_matched_url"                AS "Accepted_name.Name_matched_url"
67
, tnrs_accepted."Author_matched"                  AS "Accepted_name.Author_matched"
68
, tnrs_accepted."Author_score"                    AS "Accepted_name.Author_score"
69
, tnrs_accepted."Family_matched"                  AS "Accepted_name.Family_matched"
70
, tnrs_accepted."Family_score"                    AS "Accepted_name.Family_score"
71
, tnrs_accepted."Name_matched_accepted_family"    AS "Accepted_name.Name_matched_accepted_family"
72
, tnrs_accepted."Genus_matched"                   AS "Accepted_name.Genus_matched"
73
, tnrs_accepted."Genus_score"                     AS "Accepted_name.Genus_score"
74
, tnrs_accepted."Specific_epithet_matched"        AS "Accepted_name.Specific_epithet_matched"
75
, tnrs_accepted."Specific_epithet_score"          AS "Accepted_name.Specific_epithet_score"
76
, tnrs_accepted."Infraspecific_rank"              AS "Accepted_name.Infraspecific_rank"
77
, tnrs_accepted."Infraspecific_epithet_matched"   AS "Accepted_name.Infraspecific_epithet_matched"
78
, tnrs_accepted."Infraspecific_epithet_score"     AS "Accepted_name.Infraspecific_epithet_score"
79
, tnrs_accepted."Infraspecific_rank_2"            AS "Accepted_name.Infraspecific_rank_2"
80
, tnrs_accepted."Infraspecific_epithet_2_matched" AS "Accepted_name.Infraspecific_epithet_2_matched"
81
, tnrs_accepted."Infraspecific_epithet_2_score"   AS "Accepted_name.Infraspecific_epithet_2_score"
82
, tnrs_accepted."Annotations"                     AS "Accepted_name.Annotations"
83
, tnrs_accepted."Unmatched_terms"                 AS "Accepted_name.Unmatched_terms"
84
, tnrs_accepted."Taxonomic_status"                AS "Accepted_name.Taxonomic_status"
85
, tnrs_accepted."Accepted_name"                   AS "Accepted_name.Accepted_name"
86
, tnrs_accepted."Accepted_name_author"            AS "Accepted_name.Accepted_name_author"
87
, tnrs_accepted."Accepted_name_rank"              AS "Accepted_name.Accepted_name_rank"
88
, tnrs_accepted."Accepted_name_url"               AS "Accepted_name.Accepted_name_url"
89
, tnrs_accepted."Accepted_name_species"           AS "Accepted_name.Accepted_name_species"
90
, tnrs_accepted."Accepted_name_family"            AS "Accepted_name.Accepted_name_family"
91
, tnrs_accepted."Selected"                        AS "Accepted_name.Selected"
92
, tnrs_accepted."Source"                          AS "Accepted_name.Source"
93
, tnrs_accepted."Warnings"                        AS "Accepted_name.Warnings"
94
, tnrs_accepted."Accepted_name_lsid"              AS "Accepted_name.Accepted_name_lsid"
95
FROM tnrs
96
LEFT JOIN tnrs tnrs_accepted ON
97
tnrs_accepted."Name_submitted" = NULLIF(array_to_string(ARRAY[
98
    NULLIF(tnrs."Accepted_name_family", 'Unknown')
99
    , tnrs."Accepted_name"
100
    , tnrs."Accepted_name_author"
101
], ' '), '')
102
;
(3-3/3)