Project

General

Profile

« Previous | Next » 

Revision 13574

inputs/test_taxonomic_names/_scrub/*: updated to TNRS schema

View differences:

trunk/inputs/test_taxonomic_names/_scrub/TNRS.sql
3 3
--
4 4

  
5 5
SET statement_timeout = 0;
6
SET lock_timeout = 0;
6 7
SET client_encoding = 'UTF8';
7 8
SET standard_conforming_strings = on;
8 9
SET check_function_bodies = false;
......
17 18

  
18 19
ALTER SCHEMA "TNRS" OWNER TO bien;
19 20

  
21
--
22
-- Name: SCHEMA "TNRS"; Type: COMMENT; Schema: -; Owner: bien
23
--
24

  
25
COMMENT ON SCHEMA "TNRS" IS 'IMPORTANT: when changing this schema, you must also make the same changes on vegbiendev:
26
on vegbiendev:
27
# back up existing TNRS schema (in case of an accidental incorrect change):
28
$ make backups/TNRS.backup-remake # runtime: 3 min ("real 2m44.277s")
29
$ svn up
30
$ svn di
31
# make the changes shown in the diff
32
## to change column types:
33
SELECT util.set_col_types(''"TNRS".tnrs'', ARRAY[
34
  (''col'', ''new_type'')
35
]::util.col_cast[]); -- runtime: 9 min ("531282 ms")
36
$ rm=1 inputs/.TNRS/schema.sql.run
37
# repeat until `svn di` shows no diff
38
# back up new TNRS schema:
39
$ make backups/TNRS.backup-remake # runtime: 3 min ("real 2m44.277s")';
40

  
41

  
20 42
SET search_path = "TNRS", pg_catalog;
21 43

  
22 44
--
45
-- Name: MatchedTaxon_modify(text); Type: FUNCTION; Schema: TNRS; Owner: bien
46
--
47

  
48
CREATE FUNCTION "MatchedTaxon_modify"(view_query text) RETURNS void
49
    LANGUAGE sql
50
    AS $_$
51
SELECT util.recreate_view('"TNRS"."MatchedTaxon"', $1, $$
52
-- **IMPORTANT**: keep these updated as described in the views' comments
53

  
54
CREATE VIEW "TNRS"."ValidMatchedTaxon" AS 
55
 SELECT *
56
   FROM "TNRS"."MatchedTaxon"
57
  WHERE "MatchedTaxon".taxon_scrub__is_valid_match;
58
$$||util.mk_set_relation_metadata('"TNRS"."ValidMatchedTaxon"')||$$
59

  
60
CREATE VIEW "TNRS".taxon_scrub AS 
61
 SELECT *
62
   FROM "TNRS"."ValidMatchedTaxon"
63
   LEFT JOIN "TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name);
64
$$||util.mk_set_relation_metadata('"TNRS".taxon_scrub')||$$
65
$$);
66
$_$;
67

  
68

  
69
ALTER FUNCTION "TNRS"."MatchedTaxon_modify"(view_query text) OWNER TO bien;
70

  
71
--
72
-- Name: FUNCTION "MatchedTaxon_modify"(view_query text); Type: COMMENT; Schema: TNRS; Owner: bien
73
--
74

  
75
COMMENT ON FUNCTION "MatchedTaxon_modify"(view_query text) IS '
76
usage:
77
SELECT "TNRS"."MatchedTaxon_modify"($$
78
 SELECT *, __ AS accepted_morphospecies_binomial
79
   FROM __
80
$$);
81

  
82
idempotent
83
';
84

  
85

  
86
--
23 87
-- Name: batch__fill(); Type: FUNCTION; Schema: TNRS; Owner: bien
24 88
--
25 89

  
......
63 127
ALTER FUNCTION "TNRS".genus_is_homonym(genus text) OWNER TO bien;
64 128

  
65 129
--
66
-- Name: score_ok(double precision); Type: FUNCTION; Schema: TNRS; Owner: bien
130
-- Name: map_taxonomic_status(text, text); Type: FUNCTION; Schema: TNRS; Owner: bien
67 131
--
68 132

  
69
CREATE FUNCTION score_ok(score double precision) RETURNS boolean
70
    LANGUAGE sql IMMUTABLE STRICT
133
CREATE FUNCTION map_taxonomic_status(taxonomic_status_verbatim text, accepted_taxon_name_no_author text) RETURNS text
134
    LANGUAGE sql IMMUTABLE
71 135
    AS $_$
72
SELECT $1 >= 0.8
136
/* from http://wiki.vegpath.org/2013-11-14_conference_call#taxonomic-fields:
137
"taxonomic_status should be accepted instead of synonym when an accepted name is
138
available (this is not always the case when a name is marked as a synonym)" */
139
SELECT CASE WHEN $2 IS NOT NULL THEN 'accepted' ELSE lower($1) END
73 140
$_$;
74 141

  
75 142

  
76
ALTER FUNCTION "TNRS".score_ok(score double precision) OWNER TO bien;
143
ALTER FUNCTION "TNRS".map_taxonomic_status(taxonomic_status_verbatim text, accepted_taxon_name_no_author text) OWNER TO bien;
77 144

  
78 145
--
146
-- Name: taxon_scrub_modify(text); Type: FUNCTION; Schema: TNRS; Owner: bien
147
--
148

  
149
CREATE FUNCTION taxon_scrub_modify(view_query text) RETURNS void
150
    LANGUAGE sql
151
    AS $_$
152
SELECT util.recreate_view('"TNRS".taxon_scrub', $1);
153
$_$;
154

  
155

  
156
ALTER FUNCTION "TNRS".taxon_scrub_modify(view_query text) OWNER TO bien;
157

  
158
--
159
-- Name: FUNCTION taxon_scrub_modify(view_query text); Type: COMMENT; Schema: TNRS; Owner: bien
160
--
161

  
162
COMMENT ON FUNCTION taxon_scrub_modify(view_query text) IS '
163
usage:
164
SELECT "TNRS".taxon_scrub_modify($$
165
 SELECT *, __ AS scrubbed_morphospecies_binomial
166
   FROM "TNRS"."ValidMatchedTaxon"
167
   LEFT JOIN "TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name);
168
$$);
169

  
170
idempotent
171
';
172

  
173

  
174
--
175
-- Name: tnrs__batch_begin(); Type: FUNCTION; Schema: TNRS; Owner: bien
176
--
177

  
178
CREATE FUNCTION tnrs__batch_begin() RETURNS trigger
179
    LANGUAGE plpgsql
180
    AS $$
181
BEGIN
182
	PERFORM util.seq__reset('pg_temp.tnrs__match_num__seq', 0);
183
	RETURN NULL;
184
END;
185
$$;
186

  
187

  
188
ALTER FUNCTION "TNRS".tnrs__batch_begin() OWNER TO bien;
189

  
190
--
191
-- Name: tnrs__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: bien
192
--
193

  
194
CREATE FUNCTION tnrs__match_num__next() RETURNS bigint
195
    LANGUAGE sql
196
    AS $$
197
SELECT nextval('pg_temp.tnrs__match_num__seq');
198
$$;
199

  
200

  
201
ALTER FUNCTION "TNRS".tnrs__match_num__next() OWNER TO bien;
202

  
203
--
79 204
-- Name: tnrs_populate_fields(); Type: FUNCTION; Schema: TNRS; Owner: bien
80 205
--
81 206

  
......
83 208
    LANGUAGE plpgsql
84 209
    AS $$
85 210
DECLARE
86
    "Specific_epithet_is_plant" boolean :=
87
        (CASE
88
        WHEN   new."Infraspecific_epithet_matched"   IS NOT NULL
89
            OR new."Infraspecific_epithet_2_matched" IS NOT NULL
90
            OR new."Specific_epithet_score" >= 0.9 -- fuzzy match
91
            THEN true
92
        ELSE NULL -- ambiguous
93
        END);
94
    never_homonym boolean = COALESCE(new."Author_score" >= 0.6, false); -- author disambiguates
95
    family_is_homonym boolean = NOT never_homonym AND "TNRS".family_is_homonym(new."Family_matched");
96
    genus_is_homonym  boolean = NOT never_homonym AND "TNRS".genus_is_homonym( new."Genus_matched" );
211
	"Specific_epithet_is_plant" boolean :=
212
		(CASE
213
		WHEN   new."Infraspecific_epithet_matched"	 IS NOT NULL
214
			OR new."Infraspecific_epithet_2_matched" IS NOT NULL
215
			OR new."Specific_epithet_score" >= 0.9 -- fuzzy match
216
			THEN true
217
		ELSE NULL -- ambiguous
218
		END);
219
	never_homonym boolean = COALESCE(new."Author_score" >= 0.6, false);
220
		-- author disambiguates
221
	family_is_homonym boolean = NOT never_homonym
222
		AND "TNRS".family_is_homonym(new."Family_matched");
223
	genus_is_homonym  boolean = NOT never_homonym
224
		AND "TNRS".genus_is_homonym(new."Genus_matched");
225
	matched_taxon_name_with_author text = NULLIF(concat_ws(' '
226
		, NULLIF(NULLIF(new."Name_matched_accepted_family", 'Unknown'),
227
			new."Name_matched")
228
		, NULLIF(new."Name_matched", 'No suitable matches found.')
229
		, new."Name_matched_author"
230
		), '');
231
	accepted_taxon_name_with_author text = NULLIF(concat_ws(' '
232
		, NULLIF(NULLIF(new."Accepted_name_family", 'Unknown'),
233
			new."Accepted_name")
234
		, new."Accepted_name"
235
		, new."Accepted_name_author"
236
		), '');
97 237
BEGIN
98
    new."Accepted_scientific_name" = NULLIF(concat_ws(' '
99
        , NULLIF(NULLIF(new."Accepted_name_family", 'Unknown'), new."Accepted_name")
100
        , new."Accepted_name"
101
        , new."Accepted_name_author"
102
    ), '');
103
    new."Max_score" = GREATEST(
104
          new."Overall_score"
105
        , new."Family_score"
106
        , new."Genus_score"
107
        , new."Specific_epithet_score"
108
    );
109
    new."Is_homonym" = COALESCE(genus_is_homonym, family_is_homonym);
110
    new."Is_plant" = (CASE
111
        WHEN new."Family_score" = 1 AND NOT family_is_homonym -- exact match
112
            THEN true
113
        ELSE -- consider genus
114
            (CASE
115
            WHEN new."Genus_score" =  1    -- exact match
116
                THEN
117
                (CASE
118
                WHEN NOT genus_is_homonym THEN true
119
                ELSE "Specific_epithet_is_plant"
120
                END)
121
            WHEN new."Genus_score" >= 0.85 -- fuzzy match
122
                THEN "Specific_epithet_is_plant"
123
            ELSE NULL -- ambiguous
124
            END)
125
        END);
126
    
127
    RETURN new;
238
	/* exclude homonyms because these are not valid matches (i.e. TNRS provides
239
	a name, but the name is not meaningful because it is not unambiguous). */
240
	new.is_valid_match = new."Taxonomic_status" != 'Invalid'
241
		AND COALESCE(CASE
242
		WHEN new."Family_score" = 1 AND NOT family_is_homonym -- exact match
243
			THEN true
244
		ELSE -- consider genus
245
			(CASE
246
			WHEN new."Genus_score" =  1	   -- exact match
247
				THEN
248
				(CASE
249
				WHEN NOT genus_is_homonym THEN true
250
				ELSE "Specific_epithet_is_plant"
251
				END)
252
			WHEN new."Genus_score" >= 0.85 -- fuzzy match
253
				THEN "Specific_epithet_is_plant"
254
			ELSE NULL -- ambiguous
255
			END)
256
		END, false);
257
	new.scrubbed_unique_taxon_name = COALESCE(
258
		accepted_taxon_name_with_author, matched_taxon_name_with_author);
259
	
260
	RETURN new;
128 261
END;
129 262
$$;
130 263

  
......
137 270

  
138 271
COMMENT ON FUNCTION tnrs_populate_fields() IS 'IMPORTANT: when changing this function, you must regenerate the derived cols:
139 272
UPDATE "TNRS".tnrs SET "Name_submitted" = "Name_submitted"
140
runtime: 25 min ("5221748 rows affected, 1524228 ms execution time")
273
runtime: 30 min ("5564082 rows affected, 1918900 ms execution time")
141 274
VACUUM ANALYZE "TNRS".tnrs -- to remove previous rows
142
runtime: 1 min ("62350 ms")';
275
runtime: 1.5 min ("92633 ms")';
143 276

  
144 277

  
145 278
SET default_tablespace = '';
......
152 285

  
153 286
CREATE TABLE tnrs (
154 287
    batch text DEFAULT now() NOT NULL,
288
    match_num integer,
155 289
    "Name_number" integer NOT NULL,
156 290
    "Name_submitted" text NOT NULL,
157 291
    "Overall_score" double precision,
......
188 322
    "Source" text,
189 323
    "Warnings" text,
190 324
    "Accepted_name_lsid" text,
191
    "Accepted_scientific_name" text,
192
    "Max_score" double precision,
193
    "Is_homonym" boolean,
194
    "Is_plant" boolean
325
    is_valid_match boolean NOT NULL,
326
    scrubbed_unique_taxon_name text
195 327
);
196 328

  
197 329

  
......
201 333
-- Name: TABLE tnrs; Type: COMMENT; Schema: TNRS; Owner: bien
202 334
--
203 335

  
204
COMMENT ON TABLE tnrs IS 'IMPORTANT: when changing this table''s schema, you must regenerate data.sql:
205
$ <this_file>/../test_taxonomic_names/test_scrub
206
you must also make the same changes on vegbiendev: e.g.
207
$ make backups/TNRS.backup-remake # runtime: 3 min ("real 2m44.277s")
208
SELECT util.set_col_types(''"TNRS".tnrs'', ARRAY[
209
  (''col'', ''new_type'')
210
]::util.col_cast[]);
211
runtime: 9 min ("531282 ms")';
336
COMMENT ON TABLE tnrs IS 'IMPORTANT: when changing this table''s schema, you may need to re-run TNRS:
337
$ inputs/.TNRS/data.sql.run refresh';
212 338

  
213 339

  
214 340
--
215
-- Name: AcceptedTaxon; Type: VIEW; Schema: TNRS; Owner: bien
216
--
217

  
218
CREATE VIEW "AcceptedTaxon" AS
219
    SELECT tnrs.batch AS "*Accepted_name.batch", tnrs."Name_submitted" AS "acceptedScientificName", tnrs."Genus_matched" AS "acceptedGenus", tnrs."Specific_epithet_matched" AS "acceptedSpecificEpithet", tnrs."Infraspecific_epithet_matched" AS "acceptedInfraspecificEpithet", tnrs."Taxonomic_status" AS "acceptedTaxonomicStatus", tnrs."Selected" AS "*Accepted_name.Selected", tnrs."Source" AS "*Accepted_name.Source", tnrs."Warnings" AS "*Accepted_name.Warnings", tnrs."Accepted_name_lsid" AS "*Accepted_name.Accepted_name_lsid" FROM tnrs;
220

  
221

  
222
ALTER TABLE "TNRS"."AcceptedTaxon" OWNER TO bien;
223

  
224
--
225 341
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: bien
226 342
--
227 343

  
228 344
CREATE VIEW "MatchedTaxon" AS
229
    SELECT tnrs.batch AS "*Name_matched.batch", tnrs."Name_submitted" AS "concatenatedScientificName", tnrs."Name_matched" AS "matchedTaxonName", tnrs."Name_matched_rank" AS "matchedTaxonRank", tnrs."Name_score" AS "*Name_matched.Name_score", tnrs."Name_matched_author" AS "matchedScientificNameAuthorship", tnrs."Name_matched_url" AS "matchedScientificNameID", tnrs."Author_score" AS "*Name_matched.Author_score", tnrs."Family_score" AS "matchedFamilyConfidence_fraction", COALESCE(tnrs."Name_matched_accepted_family", tnrs."Accepted_name_family") AS "matchedFamily", tnrs."Genus_matched" AS "matchedGenus", tnrs."Genus_score" AS "matchedGenusConfidence_fraction", tnrs."Specific_epithet_matched" AS "matchedSpecificEpithet", tnrs."Specific_epithet_score" AS "matchedSpeciesConfidence_fraction", tnrs."Infraspecific_epithet_matched" AS "matchedInfraspecificEpithet", tnrs."Infraspecific_epithet_score" AS "*Name_matched.Infraspecific_epithet_score", tnrs."Annotations" AS "identificationQualifier", tnrs."Unmatched_terms" AS "morphospeciesSuffix", tnrs."Taxonomic_status" AS "taxonomicStatus", tnrs."Accepted_name" AS "acceptedTaxonName", tnrs."Accepted_name_author" AS "acceptedScientificNameAuthorship", tnrs."Accepted_name_rank" AS "acceptedTaxonRank", tnrs."Accepted_name_url" AS "acceptedScientificNameID", tnrs."Accepted_name_species" AS "*Name_matched.Accepted_name_species", tnrs."Accepted_name_family" AS "acceptedFamily", tnrs."Selected" AS "*Name_matched.Selected", tnrs."Source" AS "*Name_matched.Source", tnrs."Warnings" AS "*Name_matched.Warnings", tnrs."Accepted_name_lsid" AS "*Name_matched.Accepted_name_lsid", tnrs."Accepted_scientific_name" AS "acceptedScientificName", tnrs."Max_score" AS "matchedTaxonConfidence_fraction" FROM tnrs;
345
 SELECT s."*Name_matched.batch", 
346
    s."concatenatedScientificName", 
347
    s."matchedTaxonName", 
348
    s."matchedTaxonRank", 
349
    s."*Name_matched.Name_score", 
350
    s."matchedScientificNameAuthorship", 
351
    s."matchedScientificNameID", 
352
    s."*Name_matched.Author_score", 
353
    s."matchedFamilyConfidence_fraction", 
354
    s."matchedFamily", 
355
    s."matchedGenus", 
356
    s."matchedGenusConfidence_fraction", 
357
    s."matchedSpecificEpithet", 
358
    s."matchedSpeciesConfidence_fraction", 
359
    s."matchedInfraspecificEpithet", 
360
    s."*Name_matched.Infraspecific_epithet_score", 
361
    s."identificationQualifier", 
362
    s."morphospeciesSuffix", 
363
    s."taxonomicStatus", 
364
    s.accepted_taxon_name_no_author, 
365
    s.accepted_author, 
366
    s.accepted_taxon_rank, 
367
    s."acceptedScientificNameID", 
368
    s.accepted_species_binomial, 
369
    s.accepted_family, 
370
    s."*Name_matched.Selected", 
371
    s."*Name_matched.Source", 
372
    s."*Name_matched.Warnings", 
373
    s."*Name_matched.Accepted_name_lsid", 
374
    s.taxon_scrub__is_valid_match, 
375
    s.scrubbed_unique_taxon_name, 
376
        CASE
377
            WHEN (s.accepted_taxon_rank = 'family'::text) THEN concat_ws(' '::text, s.accepted_family, s."morphospeciesSuffix")
378
            WHEN (s.accepted_taxon_rank = 'genus'::text) THEN concat_ws(' '::text, s.accepted_taxon_name_no_author, s."morphospeciesSuffix")
379
            ELSE s.accepted_species_binomial
380
        END AS accepted_morphospecies_binomial
381
   FROM ( SELECT tnrs.batch AS "*Name_matched.batch", 
382
            tnrs."Name_submitted" AS "concatenatedScientificName", 
383
            tnrs."Name_matched" AS "matchedTaxonName", 
384
            tnrs."Name_matched_rank" AS "matchedTaxonRank", 
385
            tnrs."Name_score" AS "*Name_matched.Name_score", 
386
            tnrs."Name_matched_author" AS "matchedScientificNameAuthorship", 
387
            tnrs."Name_matched_url" AS "matchedScientificNameID", 
388
            tnrs."Author_score" AS "*Name_matched.Author_score", 
389
            tnrs."Family_score" AS "matchedFamilyConfidence_fraction", 
390
            COALESCE(tnrs."Name_matched_accepted_family", tnrs."Accepted_name_family") AS "matchedFamily", 
391
            tnrs."Genus_matched" AS "matchedGenus", 
392
            tnrs."Genus_score" AS "matchedGenusConfidence_fraction", 
393
            tnrs."Specific_epithet_matched" AS "matchedSpecificEpithet", 
394
            tnrs."Specific_epithet_score" AS "matchedSpeciesConfidence_fraction", 
395
            tnrs."Infraspecific_epithet_matched" AS "matchedInfraspecificEpithet", 
396
            tnrs."Infraspecific_epithet_score" AS "*Name_matched.Infraspecific_epithet_score", 
397
            tnrs."Annotations" AS "identificationQualifier", 
398
            tnrs."Unmatched_terms" AS "morphospeciesSuffix", 
399
            map_taxonomic_status(tnrs."Taxonomic_status", tnrs."Accepted_name") AS "taxonomicStatus", 
400
            tnrs."Accepted_name" AS accepted_taxon_name_no_author, 
401
            tnrs."Accepted_name_author" AS accepted_author, 
402
            tnrs."Accepted_name_rank" AS accepted_taxon_rank, 
403
            tnrs."Accepted_name_url" AS "acceptedScientificNameID", 
404
            tnrs."Accepted_name_species" AS accepted_species_binomial, 
405
            tnrs."Accepted_name_family" AS accepted_family, 
406
            tnrs."Selected" AS "*Name_matched.Selected", 
407
            tnrs."Source" AS "*Name_matched.Source", 
408
            tnrs."Warnings" AS "*Name_matched.Warnings", 
409
            tnrs."Accepted_name_lsid" AS "*Name_matched.Accepted_name_lsid", 
410
            tnrs.is_valid_match AS taxon_scrub__is_valid_match, 
411
            tnrs.scrubbed_unique_taxon_name
412
           FROM tnrs) s;
230 413

  
231 414

  
232 415
ALTER TABLE "TNRS"."MatchedTaxon" OWNER TO bien;
233 416

  
234 417
--
235
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: bien
418
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: bien
236 419
--
237 420

  
238
CREATE VIEW "ValidMatchedTaxon" AS
239
    SELECT "MatchedTaxon"."*Name_matched.batch", "MatchedTaxon"."concatenatedScientificName", "MatchedTaxon"."matchedTaxonName", "MatchedTaxon"."matchedTaxonRank", "MatchedTaxon"."*Name_matched.Name_score", "MatchedTaxon"."matchedScientificNameAuthorship", "MatchedTaxon"."matchedScientificNameID", "MatchedTaxon"."*Name_matched.Author_score", "MatchedTaxon"."matchedFamilyConfidence_fraction", "MatchedTaxon"."matchedFamily", "MatchedTaxon"."matchedGenus", "MatchedTaxon"."matchedGenusConfidence_fraction", "MatchedTaxon"."matchedSpecificEpithet", "MatchedTaxon"."matchedSpeciesConfidence_fraction", "MatchedTaxon"."matchedInfraspecificEpithet", "MatchedTaxon"."*Name_matched.Infraspecific_epithet_score", "MatchedTaxon"."identificationQualifier", "MatchedTaxon"."morphospeciesSuffix", "MatchedTaxon"."taxonomicStatus", "MatchedTaxon"."acceptedTaxonName", "MatchedTaxon"."acceptedScientificNameAuthorship", "MatchedTaxon"."acceptedTaxonRank", "MatchedTaxon"."acceptedScientificNameID", "MatchedTaxon"."*Name_matched.Accepted_name_species", "MatchedTaxon"."acceptedFamily", "MatchedTaxon"."*Name_matched.Selected", "MatchedTaxon"."*Name_matched.Source", "MatchedTaxon"."*Name_matched.Warnings", "MatchedTaxon"."*Name_matched.Accepted_name_lsid", "MatchedTaxon"."acceptedScientificName", "MatchedTaxon"."matchedTaxonConfidence_fraction" FROM "MatchedTaxon" WHERE score_ok("MatchedTaxon"."matchedTaxonConfidence_fraction");
421
COMMENT ON VIEW "MatchedTaxon" IS '
422
to modify:
423
SELECT "TNRS"."MatchedTaxon_modify"($$
424
 SELECT *, __ AS accepted_morphospecies_binomial
425
   FROM __
426
$$);
427
';
240 428

  
241 429

  
242
ALTER TABLE "TNRS"."ValidMatchedTaxon" OWNER TO bien;
243

  
244 430
--
245
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: bien
431
-- Name: Source; Type: TABLE; Schema: TNRS; Owner: bien; Tablespace: 
246 432
--
247 433

  
248
COMMENT ON VIEW "ValidMatchedTaxon" IS 'to update, use * as the column list';
434
CREATE TABLE "Source" (
435
    "*row_num" integer NOT NULL,
436
    "sourceType" text DEFAULT 'aggregator'::text NOT NULL,
437
    "datasetURL" text DEFAULT 'http://tnrs.iplantcollaborative.org/TNRSapp.html'::text NOT NULL,
438
    CONSTRAINT nulls_mapped CHECK (true)
439
);
249 440

  
250 441

  
442
ALTER TABLE "TNRS"."Source" OWNER TO bien;
443

  
251 444
--
252
-- Name: ScrubbedTaxon; Type: VIEW; Schema: TNRS; Owner: bien
445
-- Name: COLUMN "Source"."sourceType"; Type: COMMENT; Schema: TNRS; Owner: bien
253 446
--
254 447

  
255
CREATE VIEW "ScrubbedTaxon" AS
256
    SELECT "ValidMatchedTaxon"."acceptedScientificName", "ValidMatchedTaxon"."*Name_matched.batch", "ValidMatchedTaxon"."concatenatedScientificName", "ValidMatchedTaxon"."matchedTaxonName", "ValidMatchedTaxon"."matchedTaxonRank", "ValidMatchedTaxon"."*Name_matched.Name_score", "ValidMatchedTaxon"."matchedScientificNameAuthorship", "ValidMatchedTaxon"."matchedScientificNameID", "ValidMatchedTaxon"."*Name_matched.Author_score", "ValidMatchedTaxon"."matchedFamilyConfidence_fraction", "ValidMatchedTaxon"."matchedFamily", "ValidMatchedTaxon"."matchedGenus", "ValidMatchedTaxon"."matchedGenusConfidence_fraction", "ValidMatchedTaxon"."matchedSpecificEpithet", "ValidMatchedTaxon"."matchedSpeciesConfidence_fraction", "ValidMatchedTaxon"."matchedInfraspecificEpithet", "ValidMatchedTaxon"."*Name_matched.Infraspecific_epithet_score", "ValidMatchedTaxon"."identificationQualifier", "ValidMatchedTaxon"."morphospeciesSuffix", "ValidMatchedTaxon"."taxonomicStatus", "ValidMatchedTaxon"."acceptedTaxonName", "ValidMatchedTaxon"."acceptedScientificNameAuthorship", "ValidMatchedTaxon"."acceptedTaxonRank", "ValidMatchedTaxon"."acceptedScientificNameID", "ValidMatchedTaxon"."*Name_matched.Accepted_name_species", "ValidMatchedTaxon"."acceptedFamily", "ValidMatchedTaxon"."*Name_matched.Selected", "ValidMatchedTaxon"."*Name_matched.Source", "ValidMatchedTaxon"."*Name_matched.Warnings", "ValidMatchedTaxon"."*Name_matched.Accepted_name_lsid", "ValidMatchedTaxon"."matchedTaxonConfidence_fraction", "AcceptedTaxon"."*Accepted_name.batch", "AcceptedTaxon"."acceptedGenus", "AcceptedTaxon"."acceptedSpecificEpithet", "AcceptedTaxon"."acceptedInfraspecificEpithet", "AcceptedTaxon"."acceptedTaxonomicStatus", "AcceptedTaxon"."*Accepted_name.Selected", "AcceptedTaxon"."*Accepted_name.Source", "AcceptedTaxon"."*Accepted_name.Warnings", "AcceptedTaxon"."*Accepted_name.Accepted_name_lsid" FROM ("ValidMatchedTaxon" NATURAL LEFT JOIN "AcceptedTaxon");
448
COMMENT ON COLUMN "Source"."sourceType" IS '
449
constant
450
';
257 451

  
258 452

  
259
ALTER TABLE "TNRS"."ScrubbedTaxon" OWNER TO bien;
260

  
261 453
--
262
-- Name: VIEW "ScrubbedTaxon"; Type: COMMENT; Schema: TNRS; Owner: bien
454
-- Name: COLUMN "Source"."datasetURL"; Type: COMMENT; Schema: TNRS; Owner: bien
263 455
--
264 456

  
265
COMMENT ON VIEW "ScrubbedTaxon" IS 'to update, use * as the column list';
457
COMMENT ON COLUMN "Source"."datasetURL" IS '
458
constant
459
';
266 460

  
267 461

  
268 462
--
269
-- Name: Source; Type: TABLE; Schema: TNRS; Owner: bien; Tablespace: 
463
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: bien
270 464
--
271 465

  
272
CREATE TABLE "Source" (
273
    "*row_num" integer NOT NULL,
274
    "sourceType" text DEFAULT 'aggregator'::text NOT NULL,
275
    "datasetURL" text DEFAULT 'http://tnrs.iplantcollaborative.org/TNRSapp.html'::text NOT NULL
276
);
466
CREATE VIEW "ValidMatchedTaxon" AS
467
 SELECT "MatchedTaxon"."*Name_matched.batch", 
468
    "MatchedTaxon"."concatenatedScientificName", 
469
    "MatchedTaxon"."matchedTaxonName", 
470
    "MatchedTaxon"."matchedTaxonRank", 
471
    "MatchedTaxon"."*Name_matched.Name_score", 
472
    "MatchedTaxon"."matchedScientificNameAuthorship", 
473
    "MatchedTaxon"."matchedScientificNameID", 
474
    "MatchedTaxon"."*Name_matched.Author_score", 
475
    "MatchedTaxon"."matchedFamilyConfidence_fraction", 
476
    "MatchedTaxon"."matchedFamily", 
477
    "MatchedTaxon"."matchedGenus", 
478
    "MatchedTaxon"."matchedGenusConfidence_fraction", 
479
    "MatchedTaxon"."matchedSpecificEpithet", 
480
    "MatchedTaxon"."matchedSpeciesConfidence_fraction", 
481
    "MatchedTaxon"."matchedInfraspecificEpithet", 
482
    "MatchedTaxon"."*Name_matched.Infraspecific_epithet_score", 
483
    "MatchedTaxon"."identificationQualifier", 
484
    "MatchedTaxon"."morphospeciesSuffix", 
485
    "MatchedTaxon"."taxonomicStatus", 
486
    "MatchedTaxon".accepted_taxon_name_no_author, 
487
    "MatchedTaxon".accepted_author, 
488
    "MatchedTaxon".accepted_taxon_rank, 
489
    "MatchedTaxon"."acceptedScientificNameID", 
490
    "MatchedTaxon".accepted_species_binomial, 
491
    "MatchedTaxon".accepted_family, 
492
    "MatchedTaxon"."*Name_matched.Selected", 
493
    "MatchedTaxon"."*Name_matched.Source", 
494
    "MatchedTaxon"."*Name_matched.Warnings", 
495
    "MatchedTaxon"."*Name_matched.Accepted_name_lsid", 
496
    "MatchedTaxon".taxon_scrub__is_valid_match, 
497
    "MatchedTaxon".scrubbed_unique_taxon_name, 
498
    "MatchedTaxon".accepted_morphospecies_binomial
499
   FROM "MatchedTaxon"
500
  WHERE "MatchedTaxon".taxon_scrub__is_valid_match;
277 501

  
278 502

  
279
ALTER TABLE "TNRS"."Source" OWNER TO bien;
503
ALTER TABLE "TNRS"."ValidMatchedTaxon" OWNER TO bien;
280 504

  
281 505
--
282
-- Name: COLUMN "Source"."sourceType"; Type: COMMENT; Schema: TNRS; Owner: bien
506
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: bien
283 507
--
284 508

  
285
COMMENT ON COLUMN "Source"."sourceType" IS 'constant';
509
COMMENT ON VIEW "ValidMatchedTaxon" IS '
510
to update, use * as the column list
511
';
286 512

  
287 513

  
288 514
--
289
-- Name: COLUMN "Source"."datasetURL"; Type: COMMENT; Schema: TNRS; Owner: bien
290
--
291

  
292
COMMENT ON COLUMN "Source"."datasetURL" IS 'constant';
293

  
294

  
295
--
296 515
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: bien; Tablespace: 
297 516
--
298 517

  
......
380 599

  
381 600

  
382 601
--
602
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: bien
603
--
604

  
605
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
606
 SELECT tnrs."Name_submitted" AS scrubbed_unique_taxon_name, 
607
    tnrs."Name_matched_rank" AS scrubbed_taxon_rank, 
608
    COALESCE(tnrs."Name_matched_accepted_family", tnrs."Family_matched") AS scrubbed_family, 
609
    tnrs."Genus_matched" AS scrubbed_genus, 
610
    tnrs."Specific_epithet_matched" AS scrubbed_specific_epithet, 
611
    tnrs."Infraspecific_rank" AS scrubbed_infraspecific_rank, 
612
    tnrs."Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet, 
613
    tnrs."Name_matched_author" AS scrubbed_author, 
614
    tnrs."Name_matched" AS scrubbed_taxon_name_no_author, 
615
    (tnrs."Name_matched" || COALESCE((' '::text || tnrs."Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
616
   FROM tnrs;
617

  
618

  
619
ALTER TABLE "TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*" OWNER TO bien;
620

  
621
--
622
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: bien
623
--
624

  
625
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS 'scrubbed_family: Name_matched_accepted_family was missing from the TNRS results at one point, so Family_matched is used as a workaround to populate this. the workaround is for *accepted names only*, as no opinion names do not have an Accepted_name_family to prepend to the scrubbed name to parse.';
626

  
627

  
628
--
629
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: bien
630
--
631

  
632
CREATE VIEW taxon_scrub AS
633
 SELECT "ValidMatchedTaxon".scrubbed_unique_taxon_name, 
634
    "ValidMatchedTaxon"."*Name_matched.batch", 
635
    "ValidMatchedTaxon"."concatenatedScientificName", 
636
    "ValidMatchedTaxon"."matchedTaxonName", 
637
    "ValidMatchedTaxon"."matchedTaxonRank", 
638
    "ValidMatchedTaxon"."*Name_matched.Name_score", 
639
    "ValidMatchedTaxon"."matchedScientificNameAuthorship", 
640
    "ValidMatchedTaxon"."matchedScientificNameID", 
641
    "ValidMatchedTaxon"."*Name_matched.Author_score", 
642
    "ValidMatchedTaxon"."matchedFamilyConfidence_fraction", 
643
    "ValidMatchedTaxon"."matchedFamily", 
644
    "ValidMatchedTaxon"."matchedGenus", 
645
    "ValidMatchedTaxon"."matchedGenusConfidence_fraction", 
646
    "ValidMatchedTaxon"."matchedSpecificEpithet", 
647
    "ValidMatchedTaxon"."matchedSpeciesConfidence_fraction", 
648
    "ValidMatchedTaxon"."matchedInfraspecificEpithet", 
649
    "ValidMatchedTaxon"."*Name_matched.Infraspecific_epithet_score", 
650
    "ValidMatchedTaxon"."identificationQualifier", 
651
    "ValidMatchedTaxon"."morphospeciesSuffix", 
652
    "ValidMatchedTaxon"."taxonomicStatus", 
653
    "ValidMatchedTaxon".accepted_taxon_name_no_author, 
654
    "ValidMatchedTaxon".accepted_author, 
655
    "ValidMatchedTaxon".accepted_taxon_rank, 
656
    "ValidMatchedTaxon"."acceptedScientificNameID", 
657
    "ValidMatchedTaxon".accepted_species_binomial, 
658
    "ValidMatchedTaxon".accepted_family, 
659
    "ValidMatchedTaxon"."*Name_matched.Selected", 
660
    "ValidMatchedTaxon"."*Name_matched.Source", 
661
    "ValidMatchedTaxon"."*Name_matched.Warnings", 
662
    "ValidMatchedTaxon"."*Name_matched.Accepted_name_lsid", 
663
    "ValidMatchedTaxon".taxon_scrub__is_valid_match, 
664
    "ValidMatchedTaxon".accepted_morphospecies_binomial, 
665
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank, 
666
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family, 
667
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus, 
668
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet, 
669
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_rank, 
670
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_epithet, 
671
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_author, 
672
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author, 
673
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_with_author, 
674
        CASE
675
            WHEN ("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank = 'family'::text) THEN concat_ws(' '::text, "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family, "ValidMatchedTaxon"."morphospeciesSuffix")
676
            WHEN ("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank = 'genus'::text) THEN concat_ws(' '::text, "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author, "ValidMatchedTaxon"."morphospeciesSuffix")
677
            ELSE (("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus || ' '::text) || "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet)
678
        END AS scrubbed_morphospecies_binomial
679
   FROM ("ValidMatchedTaxon"
680
   LEFT JOIN "taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name));
681

  
682

  
683
ALTER TABLE "TNRS".taxon_scrub OWNER TO bien;
684

  
685
--
686
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: bien
687
--
688

  
689
COMMENT ON VIEW taxon_scrub IS '
690
to modify:
691
SELECT "TNRS".taxon_scrub_modify($$
692
 SELECT *, __ AS scrubbed_morphospecies_binomial
693
   FROM "TNRS"."ValidMatchedTaxon"
694
   LEFT JOIN "TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name);
695
$$);
696
';
697

  
698

  
699
--
383 700
-- Name: ~Source.map; Type: TABLE; Schema: TNRS; Owner: bien; Tablespace: 
384 701
--
385 702

  
......
398 715
--
399 716

  
400 717
COPY "Source" ("*row_num", "sourceType", "datasetURL") FROM stdin;
718
1	aggregator	http://tnrs.iplantcollaborative.org/TNRSapp.html
401 719
\.
402 720

  
403 721

  
......
406 724
--
407 725

  
408 726
COPY batch (id, id_by_time, time_submitted, client_version) FROM stdin;
409
2013-08-27 22:02:36.042579-07	2013-08-27 22:02:36.042579-07	2013-08-27 22:02:36.042579-07	\N
410
2013-08-27 22:02:41.03229-07	2013-08-27 22:02:41.03229-07	2013-08-27 22:02:41.03229-07	\N
411
2013-08-27 22:02:43.024394-07	2013-08-27 22:02:43.024394-07	2013-08-27 22:02:43.024394-07	\N
727
2014-05-31 20:04:19.706592-07	2014-05-31 20:04:19.706592-07	2014-05-31 20:04:19.706592-07	\N
728
2014-05-31 20:04:25.799698-07	2014-05-31 20:04:25.799698-07	2014-05-31 20:04:25.799698-07	\N
412 729
\.
413 730

  
414 731

  
......
432 749
-- Data for Name: tnrs; Type: TABLE DATA; Schema: TNRS; Owner: bien
433 750
--
434 751

  
435
COPY tnrs (batch, "Name_number", "Name_submitted", "Overall_score", "Name_matched", "Name_matched_rank", "Name_score", "Name_matched_author", "Name_matched_url", "Author_matched", "Author_score", "Family_matched", "Family_score", "Name_matched_accepted_family", "Genus_matched", "Genus_score", "Specific_epithet_matched", "Specific_epithet_score", "Infraspecific_rank", "Infraspecific_epithet_matched", "Infraspecific_epithet_score", "Infraspecific_rank_2", "Infraspecific_epithet_2_matched", "Infraspecific_epithet_2_score", "Annotations", "Unmatched_terms", "Taxonomic_status", "Accepted_name", "Accepted_name_author", "Accepted_name_rank", "Accepted_name_url", "Accepted_name_species", "Accepted_name_family", "Selected", "Source", "Warnings", "Accepted_name_lsid", "Accepted_scientific_name", "Max_score", "Is_homonym", "Is_plant") FROM stdin;
436
2013-08-27 22:02:36.042579-07	0	Fam_indet. Boyle#6501	0	No suitable matches found.	\N	0	\N	\N	\N	0	\N	0	\N	\N	0	\N	0	\N	\N	0	\N	\N	0	\N	\N	\N	\N	\N	\N	\N	\N	\N	true	\N	 	\N	\N	0	\N	\N
437
2013-08-27 22:02:36.042579-07	1	Poa annua var. eriolepis	1	Poa annua var. eriolepis	variety	1	E. Desv.	http://www.tropicos.org/Name/50119145	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	var.	eriolepis	1	\N	\N	\N	\N	\N	Synonym	Poa annua	L.	species	http://www.tropicos.org/Name/25509881	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua L.	1	f	t
438
2013-08-27 22:02:36.042579-07	2	Poa annua	1	Poa annua	species	1	L.	http://www.tropicos.org/Name/25509881	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa annua	L.	species	http://www.tropicos.org/Name/25509881	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua L.	1	f	t
439
2013-08-27 22:02:36.042579-07	3	Silene scouleri Hook. subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire var. grisea C.L. Hitchc. & Maguire	0.770000000000000018	Silene scouleri subsp. pringlei	subspecies	0.770000000000000018	(S. Watson) C.L. Hitchc. & Maguire	http://www.tropicos.org/Name/6303627	\N	\N	\N	\N	Caryophyllaceae	Silene	1	scouleri	1	subsp.	pringlei	1	\N	\N	\N	\N	var. grisea	Accepted	Silene scouleri subsp. pringlei	(S. Watson) C.L. Hitchc. & Maguire	subspecies	http://www.tropicos.org/Name/6303627	Silene scouleri	Caryophyllaceae	true	tropicos	 [Partial match] 	\N	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire	1	t	t
440
2013-08-27 22:02:36.042579-07	4	Fabaceae Boyle#6500	0.900000000000000022	Fabaceae	family	1	Lindl.	http://www.tropicos.org/Name/42000184	\N	\N	Fabaceae	1	Fabaceae	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Boyle#6500	Accepted	Fabaceae	Lindl.	family	http://www.tropicos.org/Name/42000184	\N	Fabaceae	true	tropicos	 	\N	Fabaceae Lindl.	1	f	t
441
2013-08-27 22:02:36.042579-07	5	Poa annua subsp. exilis	1	Poa annua subsp. exilis	subspecies	1	(Tomm. ex Freyn) Asch. & Graebn.	http://www.tropicos.org/Name/50063800	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	subsp.	exilis	1	\N	\N	\N	\N	\N	Synonym	Poa infirma	Kunth	species	http://www.tropicos.org/Name/25514158	Poa infirma	Poaceae	true	tropicos	 	\N	Poaceae Poa infirma Kunth	1	f	t
442
2013-08-27 22:02:36.042579-07	6	Poa annua ssp. exilis	1	Poa annua subsp. exilis	subspecies	1	(Tomm. ex Freyn) Asch. & Graebn.	http://www.tropicos.org/Name/50063800	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	subsp.	exilis	1	\N	\N	\N	\N	\N	Synonym	Poa infirma	Kunth	species	http://www.tropicos.org/Name/25514158	Poa infirma	Poaceae	true	tropicos	 	\N	Poaceae Poa infirma Kunth	1	f	t
443
2013-08-27 22:02:36.042579-07	7	Poa annua subvar. minima	1	Poa annua subvar. minima	subvariety	1	(Schur) Asch. & Graebn.	http://www.tropicos.org/Name/50158097	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	subvar.	minima	1	\N	\N	\N	\N	\N	Accepted	Poa annua subvar. minima	(Schur) Asch. & Graebn.	subvariety	http://www.tropicos.org/Name/50158097	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua subvar. minima (Schur) Asch. & Graebn.	1	f	t
444
2013-08-27 22:02:36.042579-07	8	Poa annua L.	1	Poa annua	species	1	L.	http://www.tropicos.org/Name/25509881	L.	1	\N	\N	Poaceae	Poa	1	annua	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa annua	L.	species	http://www.tropicos.org/Name/25509881	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua L.	1	f	t
445
2013-08-27 22:02:36.042579-07	9	Compositae indet. sp.1	0.900000000000000022	Compositae	family	1	Giseke	http://www.tropicos.org/Name/50255940	\N	\N	Compositae	1	Compositae	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	indet. sp.1	Synonym	Asteraceae	Bercht. & J. Presl	family	http://www.tropicos.org/Name/50307371	\N	Asteraceae	true	tropicos	 	\N	Asteraceae Bercht. & J. Presl	1	f	t
446
2013-08-27 22:02:36.042579-07	10	Poa annua fo. lanuginosa	1	Poa annua fo. lanuginosa	forma	1	Sennen	http://www.tropicos.org/Name/50267771	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	fo.	lanuginosa	1	\N	\N	\N	\N	\N	Synonym	Poa annua var. annua	\N	variety	http://www.tropicos.org/Name/25517736	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua var. annua	1	f	t
447
2013-08-27 22:02:36.042579-07	11	Silene scouleri subsp. pringlei var. grisea C.L. Hitchc. & Maguire	0.770000000000000018	Silene scouleri subsp. pringlei	subspecies	0.770000000000000018	(S. Watson) C.L. Hitchc. & Maguire	http://www.tropicos.org/Name/6303627	\N	\N	\N	\N	Caryophyllaceae	Silene	1	scouleri	1	subsp.	pringlei	1	\N	\N	\N	\N	var. grisea	Accepted	Silene scouleri subsp. pringlei	(S. Watson) C.L. Hitchc. & Maguire	subspecies	http://www.tropicos.org/Name/6303627	Silene scouleri	Caryophyllaceae	true	tropicos	 [Partial match] 	\N	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire	1	t	t
448
2013-08-27 22:02:36.042579-07	12	Fabaceae Inga "fuzzy leaf"	0.900000000000000022	Inga	genus	1	Mill.	http://www.tropicos.org/Name/40031040	\N	\N	Fabaceae	1	Fabaceae	Inga	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	"fuzzy leaf"	Accepted	Inga	Mill.	genus	http://www.tropicos.org/Name/40031040	\N	Fabaceae	true	tropicos	 	\N	Fabaceae Inga Mill.	1	t	t
449
2013-08-27 22:02:36.042579-07	13	Fabaceae Inga sp.3	0.900000000000000022	Inga	genus	1	Mill.	http://www.tropicos.org/Name/40031040	\N	\N	Fabaceae	1	Fabaceae	Inga	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	sp.3	Accepted	Inga	Mill.	genus	http://www.tropicos.org/Name/40031040	\N	Fabaceae	true	tropicos	 	\N	Fabaceae Inga Mill.	1	t	t
450
2013-08-27 22:02:36.042579-07	14	Fabaceae unknown #2	0.900000000000000022	Fabaceae	family	1	Lindl.	http://www.tropicos.org/Name/42000184	\N	\N	Fabaceae	1	Fabaceae	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	unknown #2	Accepted	Fabaceae	Lindl.	family	http://www.tropicos.org/Name/42000184	\N	Fabaceae	true	tropicos	 	\N	Fabaceae Lindl.	1	f	t
451
2013-08-27 22:02:41.03229-07	0	Poaceae Poa infirma Kunth	1	Poa infirma	species	1	Kunth	http://www.tropicos.org/Name/25514158	Kunth	1	Poaceae	1	Poaceae	Poa	1	infirma	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa infirma	Kunth	species	http://www.tropicos.org/Name/25514158	Poa infirma	Poaceae	true	tropicos	 	\N	Poaceae Poa infirma Kunth	1	f	t
452
2013-08-27 22:02:41.03229-07	1	Fabaceae Lindl.	0.5	Fabaceae	family	0.5	Lindl.	http://www.tropicos.org/Name/42000184	\N	\N	Fabaceae	1	Fabaceae	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Lindl.	Accepted	Fabaceae	Lindl.	family	http://www.tropicos.org/Name/42000184	\N	Fabaceae	true	tropicos	 [Partial match] 	\N	Fabaceae Lindl.	1	f	t
453
2013-08-27 22:02:41.03229-07	2	Poaceae Poa annua subvar. minima (Schur) Asch. & Graebn.	1	Poa annua subvar. minima	subvariety	1	(Schur) Asch. & Graebn.	http://www.tropicos.org/Name/50158097	(Schur) Asch. & Graebn.	1	Poaceae	1	Poaceae	Poa	1	annua	1	subvar.	minima	1	\N	\N	\N	\N	\N	Accepted	Poa annua subvar. minima	(Schur) Asch. & Graebn.	subvariety	http://www.tropicos.org/Name/50158097	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua subvar. minima (Schur) Asch. & Graebn.	1	f	t
454
2013-08-27 22:02:41.03229-07	3	Fabaceae Inga Mill.	1	Inga	genus	1	Mill.	http://www.tropicos.org/Name/40031040	Mill.	1	Fabaceae	1	Fabaceae	Inga	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Inga	Mill.	genus	http://www.tropicos.org/Name/40031040	\N	Fabaceae	true	tropicos	 	\N	Fabaceae Inga Mill.	1	f	t
455
2013-08-27 22:02:41.03229-07	4	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire	1	Silene scouleri subsp. pringlei	subspecies	1	(S. Watson) C.L. Hitchc. & Maguire	http://www.tropicos.org/Name/6303627	(S. Watson) C.L. Hitchc. & Maguire	1	Caryophyllaceae	1	Caryophyllaceae	Silene	1	scouleri	1	subsp.	pringlei	1	\N	\N	\N	\N	\N	Accepted	Silene scouleri subsp. pringlei	(S. Watson) C.L. Hitchc. & Maguire	subspecies	http://www.tropicos.org/Name/6303627	Silene scouleri	Caryophyllaceae	true	tropicos	 	\N	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire	1	f	t
456
2013-08-27 22:02:41.03229-07	5	Poaceae Poa annua L.	1	Poa annua	species	1	L.	http://www.tropicos.org/Name/25509881	L.	1	Poaceae	1	Poaceae	Poa	1	annua	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa annua	L.	species	http://www.tropicos.org/Name/25509881	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua L.	1	f	t
457
2013-08-27 22:02:41.03229-07	6	Asteraceae Bercht. & J. Presl	0.400000000000000022	Asteraceae	family	0.5	\N	http://compositae.landcareresearch.co.nz/default.aspx	\N	\N	Asteraceae	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Bercht. & J. Presl	Accepted	Asteraceae	\N	family	http://compositae.landcareresearch.co.nz/default.aspx	\N	\N	true	gcc	 [Partial match] 	\N	Asteraceae	1	f	t
458
2013-08-27 22:02:41.03229-07	7	Poaceae Poa annua var. annua	1	Poa annua var. annua	variety	1	\N	http://www.tropicos.org/Name/25517736	\N	\N	Poaceae	1	Poaceae	Poa	1	annua	1	var.	annua	1	\N	\N	\N	\N	\N	Accepted	Poa annua var. annua	\N	variety	http://www.tropicos.org/Name/25517736	Poa annua	Poaceae	true	tropicos	 	\N	Poaceae Poa annua var. annua	1	f	t
459
2013-08-27 22:02:43.024394-07	0	Asteraceae	1	Asteraceae	family	1	\N	http://compositae.landcareresearch.co.nz/default.aspx	\N	\N	Asteraceae	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Asteraceae	\N	family	http://compositae.landcareresearch.co.nz/default.aspx	\N	\N	true	gcc	 	\N	Asteraceae	1	f	t
752
COPY tnrs (batch, match_num, "Name_number", "Name_submitted", "Overall_score", "Name_matched", "Name_matched_rank", "Name_score", "Name_matched_author", "Name_matched_url", "Author_matched", "Author_score", "Family_matched", "Family_score", "Name_matched_accepted_family", "Genus_matched", "Genus_score", "Specific_epithet_matched", "Specific_epithet_score", "Infraspecific_rank", "Infraspecific_epithet_matched", "Infraspecific_epithet_score", "Infraspecific_rank_2", "Infraspecific_epithet_2_matched", "Infraspecific_epithet_2_score", "Annotations", "Unmatched_terms", "Taxonomic_status", "Accepted_name", "Accepted_name_author", "Accepted_name_rank", "Accepted_name_url", "Accepted_name_species", "Accepted_name_family", "Selected", "Source", "Warnings", "Accepted_name_lsid", is_valid_match, scrubbed_unique_taxon_name) FROM stdin;
753
2014-05-31 20:04:19.706592-07	\N	0	Fam_indet. Boyle#6501	0	No suitable matches found.	\N	0	\N	\N	\N	0	\N	0	\N	\N	0	\N	0	\N	\N	0	\N	\N	0	\N	\N	\N	\N	\N	\N	\N	\N	\N	true	\N	 	\N	f	\N
754
2014-05-31 20:04:19.706592-07	\N	1	Poa annua var. eriolepis	1	Poa annua var. eriolepis	var.	1	̉ۡ.Desv.	http://www.theplantlist.org/tpl1.1/record/kew-435206	\N	\N	\N	\N	\N	Poa	1	annua	1	var.	eriolepis	1	\N	\N	\N	\N	\N	Synonym	Poa annua	L.	species	http://www.theplantlist.org/tpl1.1/record/kew-435194	Poa annua	Poaceae	true	tpl	 	\N	t	Poaceae Poa annua L.
755
2014-05-31 20:04:19.706592-07	\N	2	Poa annua	1	Poa annua	species	1	L.	http://www.theplantlist.org/tpl1.1/record/kew-435194;http://www.tropicos.org/Name/25509881;http://plants.usda.gov/java/profile?symbol=POAN	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa annua	L.	species	http://www.theplantlist.org/tpl1.1/record/kew-435194;http://www.tropicos.org/Name/25509881;http://plants.usda.gov/java/profile?symbol=POAN	Poa annua	Poaceae	true	tpl;tropicos;usda	 	\N	t	Poaceae Poa annua L.
756
2014-05-31 20:04:19.706592-07	\N	3	Silene scouleri Hook. subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire var. grisea C.L. Hitchc. & Maguire	0.770000000000000018	Silene scouleri subsp. pringlei	subsp.	0.770000000000000018	(S. Watson) C.L. Hitchc. & Maguire	http://www.theplantlist.org/tpl1.1/record/tro-6303627	\N	\N	\N	\N	Caryophyllaceae	Silene	1	scouleri	1	subsp.	pringlei	1	\N	\N	\N	\N	var. grisea	Accepted	Silene scouleri subsp. pringlei	(S. Watson) C.L. Hitchc. & Maguire	subsp.	http://www.theplantlist.org/tpl1.1/record/tro-6303627	Silene scouleri	Caryophyllaceae	true	tpl	 [Partial match] 	\N	t	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire
757
2014-05-31 20:04:19.706592-07	\N	4	Fabaceae Boyle#6500	0.900000000000000022	Fabaceae	family	1	Lindl.	http://www.tropicos.org/Name/42000184	\N	\N	Fabaceae	1	Fabaceae	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Boyle#6500	Accepted	Fabaceae	Lindl.	family	http://www.tropicos.org/Name/42000184	\N	Fabaceae	true	tropicos	 	\N	t	Fabaceae Lindl.
758
2014-05-31 20:04:19.706592-07	\N	5	Poa annua subsp. exilis	1	Poa annua subsp. exilis	subsp.	1	(Tomm. ex Freyn.) Asch. & Graebn.	http://www.theplantlist.org/tpl1.1/record/kew-435202	\N	\N	\N	\N	\N	Poa	1	annua	1	subsp.	exilis	1	\N	\N	\N	\N	\N	Synonym	Poa infirma	Kunth	species	http://www.theplantlist.org/tpl1.1/record/kew-436189	Poa infirma	Poaceae	true	tpl	 	\N	t	Poaceae Poa infirma Kunth
759
2014-05-31 20:04:19.706592-07	\N	6	Poa annua ssp. exilis	1	Poa annua subsp. exilis	subspecies	1	(Tomm. ex Freyn) Asch. & Graebn.	http://www.tropicos.org/Name/50063800	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	subsp.	exilis	1	\N	\N	\N	\N	\N	Synonym	Poa infirma	Kunth	species	http://www.tropicos.org/Name/25514158	Poa infirma	Poaceae	true	tropicos	 	\N	t	Poaceae Poa infirma Kunth
760
2014-05-31 20:04:19.706592-07	\N	7	Poa annua subvar. minima	1	Poa annua subvar. minima	subvariety	1	(Schur) Asch. & Graebn.	http://www.tropicos.org/Name/50158097	\N	\N	\N	\N	Poaceae	Poa	1	annua	1	subvar.	minima	1	\N	\N	\N	\N	\N	Accepted	Poa annua subvar. minima	(Schur) Asch. & Graebn.	subvariety	http://www.tropicos.org/Name/50158097	Poa annua	Poaceae	true	tropicos	 	\N	t	Poaceae Poa annua subvar. minima (Schur) Asch. & Graebn.
761
2014-05-31 20:04:19.706592-07	\N	8	Poa annua L.	1	Poa annua	species	1	L.	http://www.theplantlist.org/tpl1.1/record/kew-435194;http://www.tropicos.org/Name/25509881;http://plants.usda.gov/java/profile?symbol=POAN	L.	1	\N	\N	Poaceae	Poa	1	annua	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa annua	L.	species	http://www.theplantlist.org/tpl1.1/record/kew-435194;http://www.tropicos.org/Name/25509881;http://plants.usda.gov/java/profile?symbol=POAN	Poa annua	Poaceae	true	tpl;tropicos;usda	 	\N	t	Poaceae Poa annua L.
762
2014-05-31 20:04:19.706592-07	\N	9	Compositae indet. sp.1	0.900000000000000022	Compositae	family	1	\N	http://www.theplantlist.org/1.1/browse/A/Compositae/	\N	\N	Compositae	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	indet. sp.1	Accepted	Compositae	\N	family	http://www.theplantlist.org/1.1/browse/A/Compositae/	\N	\N	true	tpl	 [Ambiguous match] 	\N	t	Compositae
763
2014-05-31 20:04:19.706592-07	\N	10	Poa annua fo. lanuginosa	1	Poa annua fo. lanuginosa	fo.	1	Sennen	http://www.theplantlist.org/tpl1.1/record/tro-50267771	\N	\N	\N	\N	\N	Poa	1	annua	1	fo.	lanuginosa	1	\N	\N	\N	\N	\N	Synonym	Poa annua	L.	species	http://www.theplantlist.org/tpl1.1/record/kew-435194	Poa annua	Poaceae	true	tpl	 	\N	t	Poaceae Poa annua L.
764
2014-05-31 20:04:19.706592-07	\N	11	Silene scouleri subsp. pringlei var. grisea C.L. Hitchc. & Maguire	0.770000000000000018	Silene scouleri subsp. pringlei	subsp.	0.770000000000000018	(S. Watson) C.L. Hitchc. & Maguire	http://www.theplantlist.org/tpl1.1/record/tro-6303627	\N	\N	\N	\N	Caryophyllaceae	Silene	1	scouleri	1	subsp.	pringlei	1	\N	\N	\N	\N	var. grisea	Accepted	Silene scouleri subsp. pringlei	(S. Watson) C.L. Hitchc. & Maguire	subsp.	http://www.theplantlist.org/tpl1.1/record/tro-6303627	Silene scouleri	Caryophyllaceae	true	tpl	 [Partial match] 	\N	t	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire
765
2014-05-31 20:04:19.706592-07	\N	12	Fabaceae Inga "fuzzy leaf"	0.900000000000000022	Inga	genus	1	\N	http://www.theplantlist.org/1.1/browse/A/Leguminosae/Inga/;http://plants.usda.gov/java/profile?symbol=INGA	\N	\N	Fabaceae	1	Fabaceae	Inga	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	"fuzzy leaf"	Accepted	Inga	\N	genus	http://www.theplantlist.org/1.1/browse/A/Leguminosae/Inga/;http://plants.usda.gov/java/profile?symbol=INGA	\N	Fabaceae	true	tpl;usda	 	\N	t	Fabaceae Inga
766
2014-05-31 20:04:19.706592-07	\N	13	Fabaceae Inga sp.3	0.900000000000000022	Inga	genus	1	\N	http://www.theplantlist.org/1.1/browse/A/Leguminosae/Inga/;http://plants.usda.gov/java/profile?symbol=INGA	\N	\N	Fabaceae	1	Fabaceae	Inga	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	sp.3	Accepted	Inga	\N	genus	http://www.theplantlist.org/1.1/browse/A/Leguminosae/Inga/;http://plants.usda.gov/java/profile?symbol=INGA	\N	Fabaceae	true	tpl;usda	 	\N	t	Fabaceae Inga
767
2014-05-31 20:04:19.706592-07	\N	14	Fabaceae unknown #2	0.900000000000000022	Fabaceae	family	1	Lindl.	http://www.tropicos.org/Name/42000184	\N	\N	Fabaceae	1	Fabaceae	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	unknown #2	Accepted	Fabaceae	Lindl.	family	http://www.tropicos.org/Name/42000184	\N	Fabaceae	true	tropicos	 	\N	t	Fabaceae Lindl.
768
2014-05-31 20:04:25.799698-07	\N	0	Poaceae Poa annua L.	1	Poa annua	species	1	L.	http://www.theplantlist.org/tpl1.1/record/kew-435194;http://www.tropicos.org/Name/25509881;http://plants.usda.gov/java/profile?symbol=POAN	L.	1	Poaceae	1	Poaceae	Poa	1	annua	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa annua	L.	species	http://www.theplantlist.org/tpl1.1/record/kew-435194;http://www.tropicos.org/Name/25509881;http://plants.usda.gov/java/profile?symbol=POAN	Poa annua	Poaceae	true	tpl;tropicos;usda	 	\N	t	Poaceae Poa annua L.
769
2014-05-31 20:04:25.799698-07	\N	1	Poaceae Poa annua subvar. minima (Schur) Asch. & Graebn.	1	Poa annua subvar. minima	subvariety	1	(Schur) Asch. & Graebn.	http://www.tropicos.org/Name/50158097	(Schur) Asch. & Graebn.	1	Poaceae	1	Poaceae	Poa	1	annua	1	subvar.	minima	1	\N	\N	\N	\N	\N	Accepted	Poa annua subvar. minima	(Schur) Asch. & Graebn.	subvariety	http://www.tropicos.org/Name/50158097	Poa annua	Poaceae	true	tropicos	 	\N	t	Poaceae Poa annua subvar. minima (Schur) Asch. & Graebn.
770
2014-05-31 20:04:25.799698-07	\N	2	Compositae	1	Compositae	family	1	\N	http://www.theplantlist.org/1.1/browse/A/Compositae/	\N	\N	Compositae	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Compositae	\N	family	http://www.theplantlist.org/1.1/browse/A/Compositae/	\N	\N	true	tpl	 [Ambiguous match] 	\N	t	Compositae
771
2014-05-31 20:04:25.799698-07	\N	3	Fabaceae Lindl.	0.5	Fabaceae	family	0.5	Lindl.	http://www.tropicos.org/Name/42000184	\N	\N	Fabaceae	1	Fabaceae	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Lindl.	Accepted	Fabaceae	Lindl.	family	http://www.tropicos.org/Name/42000184	\N	Fabaceae	true	tropicos	 [Partial match] 	\N	t	Fabaceae Lindl.
772
2014-05-31 20:04:25.799698-07	\N	4	Fabaceae Inga	1	Inga	genus	1	\N	http://www.theplantlist.org/1.1/browse/A/Leguminosae/Inga/;http://plants.usda.gov/java/profile?symbol=INGA	\N	\N	Fabaceae	1	Fabaceae	Inga	1	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Inga	\N	genus	http://www.theplantlist.org/1.1/browse/A/Leguminosae/Inga/;http://plants.usda.gov/java/profile?symbol=INGA	\N	Fabaceae	true	tpl;usda	 	\N	t	Fabaceae Inga
773
2014-05-31 20:04:25.799698-07	\N	5	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire	1	Silene scouleri subsp. pringlei	subsp.	1	(S. Watson) C.L. Hitchc. & Maguire	http://www.theplantlist.org/tpl1.1/record/tro-6303627	(S. Watson) C.L. Hitchc. & Maguire	1	Caryophyllaceae	1	Caryophyllaceae	Silene	1	scouleri	1	subsp.	pringlei	1	\N	\N	\N	\N	\N	Accepted	Silene scouleri subsp. pringlei	(S. Watson) C.L. Hitchc. & Maguire	subsp.	http://www.theplantlist.org/tpl1.1/record/tro-6303627	Silene scouleri	Caryophyllaceae	true	tpl	 	\N	t	Caryophyllaceae Silene scouleri subsp. pringlei (S. Watson) C.L. Hitchc. & Maguire
774
2014-05-31 20:04:25.799698-07	\N	6	Poaceae Poa infirma Kunth	1	Poa infirma	species	1	Kunth	http://www.theplantlist.org/tpl1.1/record/kew-436189;http://www.tropicos.org/Name/25514158;http://plants.usda.gov/java/profile?symbol=POIN30	Kunth	1	Poaceae	1	Poaceae	Poa	1	infirma	1	\N	\N	\N	\N	\N	\N	\N	\N	Accepted	Poa infirma	Kunth	species	http://www.theplantlist.org/tpl1.1/record/kew-436189;http://www.tropicos.org/Name/25514158;http://plants.usda.gov/java/profile?symbol=POIN30	Poa infirma	Poaceae	true	tpl;tropicos;usda	 	\N	t	Poaceae Poa infirma Kunth
460 775
\.
461 776

  
462 777

  
......
544 859

  
545 860

  
546 861
--
547
-- Name: tnrs_score_ok; Type: INDEX; Schema: TNRS; Owner: bien; Tablespace: 
862
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: bien; Tablespace: 
548 863
--
549 864

  
550
CREATE UNIQUE INDEX tnrs_score_ok ON tnrs USING btree ("Name_submitted") WHERE score_ok("Max_score");
865
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
551 866

  
552 867

  
553 868
--
869
-- Name: tnrs__valid_match; Type: INDEX; Schema: TNRS; Owner: bien; Tablespace: 
870
--
871

  
872
CREATE UNIQUE INDEX tnrs__valid_match ON tnrs USING btree ("Name_submitted") WHERE is_valid_match;
873

  
874

  
875
--
554 876
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: bien
555 877
--
556 878

  
......
567 889

  
568 890

  
569 891
--
892
-- Name: tnrs__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: bien
893
--
894

  
895
CREATE TRIGGER tnrs__batch_begin BEFORE INSERT ON tnrs FOR EACH STATEMENT EXECUTE PROCEDURE tnrs__batch_begin();
896

  
897

  
898
--
570 899
-- Name: tnrs_populate_fields; Type: TRIGGER; Schema: TNRS; Owner: bien
571 900
--
572 901

  
......
618 947

  
619 948

  
620 949
--
950
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: bien
951
--
952

  
953
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
954
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
955
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
956
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
957

  
958

  
959
--
960
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: bien
961
--
962

  
963
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
964
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
965
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
966
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
967

  
968

  
969
--
970
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: bien
971
--
972

  
973
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
974
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
975
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
976
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
977

  
978

  
979
--
980
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: bien
981
--
982

  
983
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
984
REVOKE ALL ON TABLE taxon_scrub FROM bien;
985
GRANT ALL ON TABLE taxon_scrub TO bien;
986
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
987

  
988

  
989
--
621 990
-- PostgreSQL database dump complete
622 991
--
623 992

  
trunk/inputs/test_taxonomic_names/_scrub/public.test_taxonomic_names.sql
3 3
--
4 4

  
5 5
SET statement_timeout = 0;
6
SET lock_timeout = 0;
6 7
SET client_encoding = 'UTF8';
7 8
SET standard_conforming_strings = on;
8 9
SET check_function_bodies = false;
......
21 22
-- Name: SCHEMA "public.test_taxonomic_names"; Type: COMMENT; Schema: -; Owner: bien
22 23
--
23 24

  
24
COMMENT ON SCHEMA "public.test_taxonomic_names" IS 'Version: public (2013-8-27 22:02:51 PDT)';
25
COMMENT ON SCHEMA "public.test_taxonomic_names" IS 'Version: public (2014-5-31 20:04:29 PDT)';
25 26

  
26 27

  
27 28
SET search_path = "public.test_taxonomic_names", pg_catalog;
......
57 58
-- Name: TYPE coordinatesource; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
58 59
--
59 60

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

  
62 65

  
63 66
--
......
80 83
-- Name: TYPE establishmentmeans_dwc; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
81 84
--
82 85

  
83
COMMENT ON TYPE establishmentmeans_dwc IS 'See <http://rs.tdwg.org/dwc/terms/#establishmentMeans>';
86
COMMENT ON TYPE establishmentmeans_dwc IS '
87
See <http://rs.tdwg.org/dwc/terms/#establishmentMeans>
88
';
84 89

  
85 90

  
86 91
--
......
177 182
-- Name: TYPE placerank; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
178 183
--
179 184

  
180
COMMENT ON TYPE placerank IS 'county = parish, canton
185
COMMENT ON TYPE placerank IS '
186
county = parish, canton
181 187
municipality = city
182 188

  
183
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>';
189
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>
190
';
184 191

  
185 192

  
186 193
--
......
274 281
-- Name: TYPE taxonrank; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
275 282
--
276 283

  
277
COMMENT ON TYPE taxonrank IS 'From <http://www.tdwg.org/standards/117/download/>';
284
COMMENT ON TYPE taxonrank IS '
285
From <http://www.tdwg.org/standards/117/download/>
286
';
278 287

  
279 288

  
280 289
--
......
343 352
-- Name: TYPE role; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
344 353
--
345 354

  
346
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.';
355
COMMENT ON TYPE role IS '
356
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.
357
';
347 358

  
348 359

  
349 360
--
361
-- Name: schema_anchor; Type: TYPE; Schema: public.test_taxonomic_names; Owner: bien
362
--
363

  
364
CREATE TYPE schema_anchor AS (
365
);
366

  
367

  
368
ALTER TYPE "public.test_taxonomic_names".schema_anchor OWNER TO bien;
369

  
370
--
371
-- Name: TYPE schema_anchor; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
372
--
373

  
374
COMMENT ON TYPE schema_anchor IS 'used with schema_anchor params';
375

  
376

  
377
--
350 378
-- Name: sourcetype; Type: TYPE; Schema: public.test_taxonomic_names; Owner: bien
351 379
--
352 380

  
......
377 405
-- Name: TYPE sourcetype; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
378 406
--
379 407

  
380
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>';
408
COMMENT ON TYPE sourcetype IS '
409
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>
410
';
381 411

  
382 412

  
383 413
--
......
417 447
-- Name: TYPE taxonclass; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
418 448
--
419 449

  
420
COMMENT ON TYPE taxonclass IS '= growthform + establishmentmeans_dwc + some others';
450
COMMENT ON TYPE taxonclass IS '
451
= growthform + establishmentmeans_dwc + some others
452
';
421 453

  
422 454

  
423 455
--
......
439 471
-- Name: TYPE taxonomic_status; Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
440 472
--
441 473

  
442
COMMENT ON TYPE taxonomic_status IS 'See <http://tnrs.iplantcollaborative.org/instructions.html#Status>';
474
COMMENT ON TYPE taxonomic_status IS '
475
See <http://tnrs.iplantcollaborative.org/instructions.html#Status>
476
';
443 477

  
444 478

  
445 479
--
......
447 481
--
448 482

  
449 483
CREATE FUNCTION _cm_to_m(value double precision) RETURNS double precision
450
    LANGUAGE sql IMMUTABLE STRICT
484
    LANGUAGE sql IMMUTABLE
451 485
    AS $_$
452 486
SELECT $1/100.
453 487
$_$;
......
460 494
--
461 495

  
462 496
CREATE FUNCTION _filter_genus(value text) RETURNS text
463
    LANGUAGE sql IMMUTABLE STRICT
497
    LANGUAGE sql IMMUTABLE
464 498
    AS $_$
465 499
SELECT (CASE WHEN $1 ~ '\d' THEN NULL ELSE $1 END)
466 500
$_$;
......
473 507
--
474 508

  
475 509
CREATE FUNCTION _fraction_to_percent(value double precision) RETURNS double precision
476
    LANGUAGE sql IMMUTABLE STRICT
510
    LANGUAGE sql IMMUTABLE
477 511
    AS $_$
478 512
SELECT $1*100.
479 513
$_$;
......
486 520
--
487 521

  
488 522
CREATE FUNCTION _ft_to_m(value double precision) RETURNS double precision
489
    LANGUAGE sql IMMUTABLE STRICT
523
    LANGUAGE sql IMMUTABLE
490 524
    AS $_$
491 525
SELECT _in_to_m($1*12)
492 526
$_$;
......
499 533
--
500 534

  
501 535
CREATE FUNCTION _ha_to_m2(value double precision) RETURNS double precision
502
    LANGUAGE sql IMMUTABLE STRICT
536
    LANGUAGE sql IMMUTABLE
503 537
    AS $_$
504 538
SELECT $1*10000.
505 539
$_$;
......
512 546
--
513 547

  
514 548
CREATE FUNCTION _has_taxonomic_name(rank taxonrank) RETURNS boolean
515
    LANGUAGE sql IMMUTABLE STRICT
549
    LANGUAGE sql IMMUTABLE
516 550
    AS $_$
517 551
SELECT $1 >= 'family'
518 552
$_$;
......
525 559
--
526 560

  
527 561
CREATE FUNCTION _in_to_m(value double precision) RETURNS double precision
528
    LANGUAGE sql IMMUTABLE STRICT
562
    LANGUAGE sql IMMUTABLE
529 563
    AS $_$
530 564
SELECT $1*2.54/100.
531 565
$_$;
......
538 572
--
539 573

  
540 574
CREATE FUNCTION _km_to_m(value double precision) RETURNS double precision
541
    LANGUAGE sql IMMUTABLE STRICT
575
    LANGUAGE sql IMMUTABLE
542 576
    AS $_$
543
SELECT $1*1000.
577
SELECT util._km_to_m($1)
544 578
$_$;
545 579

  
546 580

  
......
551 585
--
552 586

  
553 587
CREATE FUNCTION _locationnarrative_is_cultivated(locationnarrative text) RETURNS boolean
554
    LANGUAGE sql IMMUTABLE STRICT
588
    LANGUAGE sql IMMUTABLE
555 589
    AS $_$
556 590
SELECT bool_or(value)
557 591
FROM
......
587 621
--
588 622

  
589 623
CREATE FUNCTION _m2_to_ha(value double precision) RETURNS double precision
590
    LANGUAGE sql IMMUTABLE STRICT
624
    LANGUAGE sql IMMUTABLE
591 625
    AS $_$
592 626
SELECT $1/10000.
593 627
$_$;
......
600 634
--
601 635

  
602 636
CREATE FUNCTION _m_to_cm(value double precision) RETURNS double precision
603
    LANGUAGE sql IMMUTABLE STRICT
637
    LANGUAGE sql IMMUTABLE
604 638
    AS $_$
605 639
SELECT $1*100.
606 640
$_$;
......
613 647
--
614 648

  
615 649
CREATE FUNCTION _m_to_km(value double precision) RETURNS double precision
616
    LANGUAGE sql IMMUTABLE STRICT
650
    LANGUAGE sql IMMUTABLE
617 651
    AS $_$
618 652
SELECT $1/1000.
619 653
$_$;
......
626 660
--
627 661

  
628 662
CREATE FUNCTION _mm_to_m(value double precision) RETURNS double precision
629
    LANGUAGE sql IMMUTABLE STRICT
663
    LANGUAGE sql IMMUTABLE
630 664
    AS $_$
631 665
SELECT $1/1000.
632 666
$_$;
......
660 694
-- Name: FUNCTION _or("0" boolean, "1" boolean, "2" boolean, "3" boolean, "4" boolean); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
661 695
--
662 696

  
663
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.';
697
COMMENT ON FUNCTION _or("0" boolean, "1" boolean, "2" boolean, "3" boolean, "4" boolean) IS '
698
_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.
699
';
664 700

  
665 701

  
666 702
--
......
668 704
--
669 705

  
670 706
CREATE FUNCTION _percent_to_fraction(value double precision) RETURNS double precision
671
    LANGUAGE sql IMMUTABLE STRICT
707
    LANGUAGE sql IMMUTABLE
672 708
    AS $_$
673 709
SELECT $1/100.
674 710
$_$;
......
681 717
--
682 718

  
683 719
CREATE FUNCTION _taxon_family_require_std(family text) RETURNS text
684
    LANGUAGE sql IMMUTABLE STRICT
720
    LANGUAGE sql IMMUTABLE
685 721
    AS $_$
686 722
SELECT (CASE WHEN
687 723
    lower($1) LIKE '%aceae'
......
701 737
ALTER FUNCTION "public.test_taxonomic_names"._taxon_family_require_std(family text) OWNER TO bien;
702 738

  
703 739
--
704
-- Name: _taxonlabel_set_matched_label_id(integer, integer, double precision); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
740
-- Name: _taxonlabel_set_parent_id(integer, integer); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
705 741
--
706 742

  
707
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
743
CREATE FUNCTION _taxonlabel_set_parent_id(taxonlabel_id integer, parent_id integer) RETURNS integer
744
    LANGUAGE sql
745
    AS $_$
746
UPDATE taxonlabel SET parent_id = $2 WHERE taxonlabel_id = $1 RETURNING $1
747
$_$;
748

  
749

  
750
ALTER FUNCTION "public.test_taxonomic_names"._taxonlabel_set_parent_id(taxonlabel_id integer, parent_id integer) OWNER TO bien;
751

  
752
--
753
-- Name: _taxonomic_name_is_epithet(taxonrank); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
754
--
755

  
756
CREATE FUNCTION _taxonomic_name_is_epithet(rank taxonrank) RETURNS boolean
757
    LANGUAGE sql IMMUTABLE
758
    AS $_$
759
SELECT $1 <= 'genus'
760
$_$;
761

  
762

  
763
ALTER FUNCTION "public.test_taxonomic_names"._taxonomic_name_is_epithet(rank taxonrank) OWNER TO bien;
764

  
765
--
766
-- Name: datasource_publish(text, anyelement); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
767
--
768

  
769
CREATE FUNCTION datasource_publish(datasource text, schema_anchor anyelement DEFAULT NULL::schema_anchor) RETURNS void
708 770
    LANGUAGE plpgsql
771
    SET search_path TO pg_temp
709 772
    AS $$
773
/* must use LANGUAGE plpgsql because LANGUAGE sql does not support runtime
774
changes of search_path (schema elements are bound at inline time rather than
775
runtime) */
776
/* function option search_path is needed to limit the effects of
777
`SET LOCAL search_path` to the current function */
778
DECLARE
779
	live_datasource text;
710 780
BEGIN
711
    -- Use EXECUTE to avoid caching query plan
712
    EXECUTE '
713
    UPDATE taxonlabel SET
714
      matched_label_id = '||quote_nullable(matched_label_id)||'
715
    , matched_label_fit_fraction = '
716
        ||quote_nullable(matched_label_fit_fraction)||'
717
    WHERE taxonlabel_id = '||quote_nullable(taxonlabel_id)||'
718
    ';
719
    
720
    RETURN taxonlabel_id;
781
	PERFORM util.use_schema(schema_anchor);
782
	
783
	live_datasource = rm_version_suffix(datasource);
784
	
785
	-- don't datasource_rm() the datasource to publish!
786
	IF live_datasource = datasource THEN RETURN; END IF;
787
	
788
	PERFORM datasource_rm(live_datasource, schema_anchor);
789
	PERFORM datasource_rename(datasource, live_datasource, schema_anchor);
721 790
END;
722 791
$$;
723 792

  
724 793

  
725
ALTER FUNCTION "public.test_taxonomic_names"._taxonlabel_set_matched_label_id(taxonlabel_id integer, matched_label_id integer, matched_label_fit_fraction double precision) OWNER TO bien;
794
ALTER FUNCTION "public.test_taxonomic_names".datasource_publish(datasource text, schema_anchor anyelement) OWNER TO bien;
726 795

  
727 796
--
728
-- Name: _taxonlabel_set_parent_id(integer, integer); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
797
-- Name: FUNCTION datasource_publish(datasource text, schema_anchor anyelement); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
729 798
--
730 799

  
731
CREATE FUNCTION _taxonlabel_set_parent_id(taxonlabel_id integer, parent_id integer) RETURNS integer
800
COMMENT ON FUNCTION datasource_publish(datasource text, schema_anchor anyelement) IS '
801
secure against renamings of the public schema.
802

  
803
schema_anchor: identifies this function''s schema. should be left as the default.
804
';
805

  
806

  
807
--
808
-- Name: datasource_rename(text, text, anyelement); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
809
--
810

  
811
CREATE FUNCTION datasource_rename(old text, new text, schema_anchor anyelement DEFAULT NULL::schema_anchor) RETURNS void
732 812
    LANGUAGE plpgsql
813
    SET search_path TO pg_temp
733 814
    AS $$
815
/* must use LANGUAGE plpgsql because LANGUAGE sql does not support runtime
816
changes of search_path (schema elements are bound at inline time rather than
817
runtime) */
818
/* function option search_path is needed to limit the effects of
819
`SET LOCAL search_path` to the current function */
734 820
BEGIN
735
    -- Use EXECUTE to avoid caching query plan
736
    EXECUTE '
737
    UPDATE taxonlabel SET parent_id = '||quote_nullable(parent_id)||'
738
    WHERE taxonlabel_id = '||quote_nullable(taxonlabel_id)||'
739
    ';
740
    
741
    RETURN taxonlabel_id;
821
	PERFORM util.use_schema(schema_anchor);
822
	UPDATE source SET shortname = new WHERE shortname = old;
742 823
END;
743 824
$$;
744 825

  
745 826

  
746
ALTER FUNCTION "public.test_taxonomic_names"._taxonlabel_set_parent_id(taxonlabel_id integer, parent_id integer) OWNER TO bien;
827
ALTER FUNCTION "public.test_taxonomic_names".datasource_rename(old text, new text, schema_anchor anyelement) OWNER TO bien;
747 828

  
748 829
--
749
-- Name: _taxonomic_name_is_epithet(taxonrank); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
830
-- Name: FUNCTION datasource_rename(old text, new text, schema_anchor anyelement); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
750 831
--
751 832

  
752
CREATE FUNCTION _taxonomic_name_is_epithet(rank taxonrank) RETURNS boolean
753
    LANGUAGE sql IMMUTABLE STRICT
754
    AS $_$
755
SELECT $1 <= 'genus'
756
$_$;
833
COMMENT ON FUNCTION datasource_rename(old text, new text, schema_anchor anyelement) IS '
834
secure against renamings of the public schema.
757 835

  
836
schema_anchor: identifies this function''s schema. should be left as the default.
837
';
758 838

  
759
ALTER FUNCTION "public.test_taxonomic_names"._taxonomic_name_is_epithet(rank taxonrank) OWNER TO bien;
760 839

  
761 840
--
841
-- Name: datasource_rm(text, anyelement); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
842
--
843

  
844
CREATE FUNCTION datasource_rm(datasource text, schema_anchor anyelement DEFAULT NULL::schema_anchor) RETURNS void
845
    LANGUAGE plpgsql
846
    SET search_path TO pg_temp
847
    AS $$
848
/* must use LANGUAGE plpgsql because LANGUAGE sql does not support runtime
849
changes of search_path (schema elements are bound at inline time rather than
850
runtime) */
851
/* function option search_path is needed to limit the effects of
852
`SET LOCAL search_path` to the current function */
853
BEGIN
854
	PERFORM util.use_schema(schema_anchor);
855
	DELETE FROM source WHERE shortname = datasource;
856
END;
857
$$;
858

  
859

  
860
ALTER FUNCTION "public.test_taxonomic_names".datasource_rm(datasource text, schema_anchor anyelement) OWNER TO bien;
861

  
862
--
863
-- Name: FUNCTION datasource_rm(datasource text, schema_anchor anyelement); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
864
--
865

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

  
869
schema_anchor: identifies this function''s schema. should be left as the default.
870

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

  
876
to calculate runtime:
877
BEGIN;
878
SELECT datasource_rm(''datasource'');
879
ROLLBACK;
880
';
881

  
882

  
883
--
884
-- Name: datasource_unpublish(text, anyelement); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
885
--
886

  
887
CREATE FUNCTION datasource_unpublish(datasource text, schema_anchor anyelement DEFAULT NULL::schema_anchor) RETURNS void
888
    LANGUAGE plpgsql
889
    SET search_path TO pg_temp
890
    AS $$
891
/* must use LANGUAGE plpgsql because LANGUAGE sql does not support runtime
892
changes of search_path (schema elements are bound at inline time rather than
893
runtime) */
894
/* function option search_path is needed to limit the effects of
895
`SET LOCAL search_path` to the current function */
896
BEGIN
897
	PERFORM util.use_schema(schema_anchor);
898
	PERFORM datasource_rename(datasource, datasource||'.new');
899
END;
900
$$;
901

  
902

  
903
ALTER FUNCTION "public.test_taxonomic_names".datasource_unpublish(datasource text, schema_anchor anyelement) OWNER TO bien;
904

  
905
--
906
-- Name: FUNCTION datasource_unpublish(datasource text, schema_anchor anyelement); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
907
--
908

  
909
COMMENT ON FUNCTION datasource_unpublish(datasource text, schema_anchor anyelement) IS '
910
secure against renamings of the public schema.
911

  
912
schema_anchor: identifies this function''s schema. should be left as the default.
913
';
914

  
915

  
916
--
762 917
-- Name: delete_scrubbed_taxondeterminations(text); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
763 918
--
764 919

  
......
768 923
DELETE FROM taxondetermination
769 924
USING taxonoccurrence
770 925
WHERE
771
    taxonoccurrence.source_id = source_by_shortname($1)
926
    taxonoccurrence.source_id = (SELECT source_by_shortname($1))
772 927
AND taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id
773
AND taxondetermination.source_id = source_by_shortname('TNRS')
928
AND taxondetermination.source_id = (SELECT source_by_shortname('TNRS'))
774 929
$_$;
775 930

  
776 931

  
777 932
ALTER FUNCTION "public.test_taxonomic_names".delete_scrubbed_taxondeterminations(datasource text) OWNER TO bien;
778 933

  
779 934
--
935
-- Name: location__pull_forward_from_parent(); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
936
--
937

  
938
CREATE FUNCTION location__pull_forward_from_parent() RETURNS trigger
939
    LANGUAGE plpgsql
940
    AS $$
941
DECLARE
942
	parent location;
943
BEGIN
944
	SELECT * INTO parent FROM location WHERE location_id = new.parent_id;
945
	
946
	IF new.place_id IS NULL THEN new.place_id = parent.place_id; END IF;
947
	
948
	RETURN new;
949
END;
950
$$;
951

  
952

  
953
ALTER FUNCTION "public.test_taxonomic_names".location__pull_forward_from_parent() OWNER TO bien;
954

  
955
--
956
-- Name: FUNCTION location__pull_forward_from_parent(); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
957
--
958

  
959
COMMENT ON FUNCTION location__pull_forward_from_parent() IS '
960
see wiki.vegpath.org/Pull-forward
961
';
962

  
963

  
964
--
965
-- Name: location_set_plot_location_id(); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
966
--
967

  
968
CREATE FUNCTION location_set_plot_location_id() RETURNS trigger
969
    LANGUAGE plpgsql
970
    AS $$
971
BEGIN
972
	new.plot_location_id = (CASE WHEN new.parent_id IS NULL
973
		THEN new.location_id
974
		ELSE (SELECT plot_location_id FROM location WHERE location_id = new.parent_id)
975
		END);
976
	RETURN new;
977
END;
978
$$;
979

  
980

  
981
ALTER FUNCTION "public.test_taxonomic_names".location_set_plot_location_id() OWNER TO bien;
982

  
983
--
984
-- Name: locationevent__communities(integer); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
985
--
986

  
987
CREATE FUNCTION locationevent__communities(locationevent_id integer) RETURNS SETOF text
988
    LANGUAGE sql STABLE
989
    AS $_$
990
SELECT commdescription
991
FROM      commclass
992
/* inner-join to commdetermination instead of left-joining, so that this does
993
not produce community entries (which occur because there is one commclass per
994
locationevent, but only some commclasses will then have a commdetermination) */
995
JOIN      commdetermination USING (commclass_id)
996
LEFT JOIN commconcept       USING (commconcept_id)
997
WHERE locationevent_id = $1
998
ORDER BY commdescription
999
$_$;
1000

  
1001

  
1002
ALTER FUNCTION "public.test_taxonomic_names".locationevent__communities(locationevent_id integer) OWNER TO bien;
1003

  
1004
--
1005
-- Name: locationevent__communities__array(integer); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
1006
--
1007

  
1008
CREATE FUNCTION locationevent__communities__array(locationevent_id integer) RETURNS text[]
1009
    LANGUAGE sql STABLE
1010
    AS $_$
1011
SELECT array_agg(locationevent__communities)
1012
FROM locationevent__communities($1)
1013
$_$;
1014

  
1015

  
1016
ALTER FUNCTION "public.test_taxonomic_names".locationevent__communities__array(locationevent_id integer) OWNER TO bien;
1017

  
1018
--
1019
-- Name: locationevent__contributors(integer); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
1020
--
1021

  
1022
CREATE FUNCTION locationevent__contributors(locationevent_id integer) RETURNS SETOF text
1023
    LANGUAGE sql STABLE
1024
    AS $_$
1025
SELECT fullname
1026
FROM locationeventcontributor
1027
LEFT JOIN party USING (party_id)
1028
WHERE locationevent_id = $1
1029
ORDER BY fullname
1030
$_$;
1031

  
1032

  
1033
ALTER FUNCTION "public.test_taxonomic_names".locationevent__contributors(locationevent_id integer) OWNER TO bien;
1034

  
1035
--
1036
-- Name: locationevent__contributors__array(integer); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
1037
--
1038

  
1039
CREATE FUNCTION locationevent__contributors__array(locationevent_id integer) RETURNS text[]
1040
    LANGUAGE sql STABLE
1041
    AS $_$
1042
SELECT array_agg(locationevent__contributors)
1043
FROM locationevent__contributors($1)
1044
$_$;
1045

  
1046

  
1047
ALTER FUNCTION "public.test_taxonomic_names".locationevent__contributors__array(locationevent_id integer) OWNER TO bien;
1048

  
1049
--
1050
-- Name: locationevent_pull_forward_from_parent(); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
1051
--
1052

  
1053
CREATE FUNCTION locationevent_pull_forward_from_parent() RETURNS trigger
1054
    LANGUAGE plpgsql
1055
    AS $$
1056
DECLARE
1057
	parent locationevent;
1058
BEGIN
1059
	SELECT * INTO parent FROM locationevent WHERE locationevent_id = new.parent_id;
1060
	
1061
	IF new.project_id IS NULL THEN new.project_id = parent.project_id; END IF;
1062
	
1063
	RETURN new;
1064
END;
1065
$$;
1066

  
1067

  
1068
ALTER FUNCTION "public.test_taxonomic_names".locationevent_pull_forward_from_parent() OWNER TO bien;
1069

  
1070
--
1071
-- Name: FUNCTION locationevent_pull_forward_from_parent(); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
1072
--
1073

  
1074
COMMENT ON FUNCTION locationevent_pull_forward_from_parent() IS '
1075
see wiki.vegpath.org/Pull-forward
1076
';
1077

  
1078

  
1079
--
1080
-- Name: locationevent_pull_forward_from_parent_for_stratum(); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
1081
--
1082

  
1083
CREATE FUNCTION locationevent_pull_forward_from_parent_for_stratum() RETURNS trigger
1084
    LANGUAGE plpgsql
1085
    AS $$
1086
DECLARE
1087
	parent locationevent;
1088
BEGIN
1089
	SELECT * INTO parent FROM locationevent WHERE locationevent_id = new.parent_id;
1090
	
1091
	IF new.location_id IS NULL THEN new.location_id = parent.location_id; END IF;
1092
	
1093
	RETURN new;
1094
END;
1095
$$;
1096

  
1097

  
1098
ALTER FUNCTION "public.test_taxonomic_names".locationevent_pull_forward_from_parent_for_stratum() OWNER TO bien;
1099

  
1100
--
1101
-- Name: FUNCTION locationevent_pull_forward_from_parent_for_stratum(); Type: COMMENT; Schema: public.test_taxonomic_names; Owner: bien
1102
--
1103

  
1104
COMMENT ON FUNCTION locationevent_pull_forward_from_parent_for_stratum() IS '
1105
see wiki.vegpath.org/Pull-forward
1106
';
1107

  
1108

  
1109
--
1110
-- Name: locationevent_set_place_visit_id(); Type: FUNCTION; Schema: public.test_taxonomic_names; Owner: bien
1111
--
1112

  
1113
CREATE FUNCTION locationevent_set_place_visit_id() RETURNS trigger
1114
    LANGUAGE plpgsql
1115
    AS $$
1116
BEGIN
1117
	new.place_visit_id = (CASE WHEN new.parent_id IS NULL
1118
		THEN new.locationevent_id
1119
		ELSE (SELECT place_visit_id FROM locationevent WHERE locationevent_id = new.parent_id)
1120
		END);
1121
	RETURN new;
1122
END;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff