Project

General

Profile

1
--
2
-- PostgreSQL database dump
3
--
4

    
5
SET statement_timeout = 0;
6
SET lock_timeout = 0;
7
SET client_encoding = 'UTF8';
8
SET standard_conforming_strings = on;
9
SET check_function_bodies = false;
10
SET client_min_messages = warning;
11

    
12
--
13
-- Name: TNRS; Type: SCHEMA; Schema: -; Owner: -
14
--
15

    
16
--CREATE SCHEMA "TNRS";
17

    
18

    
19
--
20
-- Name: SCHEMA "TNRS"; Type: COMMENT; Schema: -; Owner: -
21
--
22

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

    
41

    
42
SET search_path = "TNRS", pg_catalog;
43

    
44
--
45
-- Name: batch__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
46
--
47

    
48
CREATE FUNCTION batch__fill() RETURNS trigger
49
    LANGUAGE plpgsql
50
    AS $$
51
BEGIN
52
	new.id_by_time = new.time_submitted;
53
	new.id = COALESCE(new.id, new.id_by_time);
54
	RETURN new;
55
END;
56
$$;
57

    
58

    
59
--
60
-- Name: family_is_homonym(text); Type: FUNCTION; Schema: TNRS; Owner: -
61
--
62

    
63
CREATE FUNCTION family_is_homonym(family text) RETURNS boolean
64
    LANGUAGE sql STABLE STRICT
65
    AS $_$
66
SELECT EXISTS(SELECT * FROM "IRMNG".family_homonym_epithet WHERE "taxonNameOrEpithet" = $1)
67
$_$;
68

    
69

    
70
--
71
-- Name: genus_is_homonym(text); Type: FUNCTION; Schema: TNRS; Owner: -
72
--
73

    
74
CREATE FUNCTION genus_is_homonym(genus text) RETURNS boolean
75
    LANGUAGE sql STABLE STRICT
76
    AS $_$
77
SELECT EXISTS(SELECT * FROM "IRMNG".genus_homonym_epithet WHERE "taxonNameOrEpithet" = $1)
78
$_$;
79

    
80

    
81
--
82
-- Name: map_taxonomic_status(text, text); Type: FUNCTION; Schema: TNRS; Owner: -
83
--
84

    
85
CREATE FUNCTION map_taxonomic_status(taxonomic_status_verbatim text, accepted_taxon_name_no_author text) RETURNS text
86
    LANGUAGE sql IMMUTABLE
87
    AS $_$
88
/* from http://wiki.vegpath.org/2013-11-14_conference_call#taxonomic-fields:
89
"taxonomic_status should be accepted instead of synonym when an accepted name is
90
available (this is not always the case when a name is marked as a synonym)" */
91
SELECT CASE WHEN $2 IS NOT NULL THEN 'accepted' ELSE lower($1) END
92
$_$;
93

    
94

    
95
--
96
-- Name: remove_prefix(text, text, boolean, boolean); Type: FUNCTION; Schema: TNRS; Owner: -
97
--
98

    
99
CREATE FUNCTION remove_prefix(prefix text, str text, require boolean DEFAULT true, case_sensitive boolean DEFAULT true) RETURNS text
100
    LANGUAGE sql IMMUTABLE
101
    AS $$
102
SELECT util.remove_prefix(prefix, str, require, case_sensitive)
103
$$;
104

    
105

    
106
--
107
-- Name: FUNCTION remove_prefix(prefix text, str text, require boolean, case_sensitive boolean); Type: COMMENT; Schema: TNRS; Owner: -
108
--
109

    
110
COMMENT ON FUNCTION remove_prefix(prefix text, str text, require boolean, case_sensitive boolean) IS '
111
wrapper that prevents views from getting dropped when the util schema is reinstalled
112
';
113

    
114

    
115
--
116
-- Name: taxon_match__batch_begin(); Type: FUNCTION; Schema: TNRS; Owner: -
117
--
118

    
119
CREATE FUNCTION taxon_match__batch_begin() RETURNS trigger
120
    LANGUAGE plpgsql
121
    AS $$
122
BEGIN
123
	PERFORM util.seq__reset('pg_temp.taxon_match__match_num__seq', 0);
124
	RETURN NULL;
125
END;
126
$$;
127

    
128

    
129
--
130
-- Name: taxon_match__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
131
--
132

    
133
CREATE FUNCTION taxon_match__fill() RETURNS trigger
134
    LANGUAGE plpgsql
135
    AS $$
136
BEGIN
137
	DECLARE
138
		"Specific_epithet_is_plant" boolean :=
139
			(CASE
140
			WHEN   new."*Infraspecific_epithet_matched"	 IS NOT NULL
141
				OR new."*Infraspecific_epithet_2_matched" IS NOT NULL
142
				OR new."*Specific_epithet_score" >= 0.9 -- fuzzy match
143
				THEN true
144
			ELSE NULL -- ambiguous
145
			END);
146
		never_homonym boolean = COALESCE(new."*Author_score" >= 0.6, false);
147
			-- author disambiguates
148
		family_is_homonym boolean = NOT never_homonym
149
			AND "TNRS".family_is_homonym(new."*Family_matched");
150
		genus_is_homonym  boolean = NOT never_homonym
151
			AND "TNRS".genus_is_homonym(new."*Genus_matched");
152
	BEGIN
153
		/* exclude homonyms because these are not valid matches (TNRS provides a
154
		name, but the name is not meaningful because it is not unambiguous) */
155
		new.is_valid_match = new."*Taxonomic_status" != 'Invalid'
156
			AND COALESCE(CASE
157
			WHEN new."*Family_score" = 1 AND NOT family_is_homonym -- exact match
158
				THEN true
159
			ELSE -- consider genus
160
				(CASE
161
				WHEN new."*Genus_score" =  1	   -- exact match
162
					THEN
163
					(CASE
164
					WHEN NOT genus_is_homonym THEN true
165
					ELSE "Specific_epithet_is_plant"
166
					END)
167
				WHEN new."*Genus_score" >= 0.85 -- fuzzy match
168
					THEN "Specific_epithet_is_plant"
169
				ELSE NULL -- ambiguous
170
				END)
171
			END, false);
172
	END;
173
	
174
	DECLARE
175
		matched_taxon_name_with_author text = NULLIF(concat_ws(' '
176
			, NULLIF(NULLIF(new."*Name_matched_accepted_family", 'Unknown'),
177
				new."*Name_matched")
178
			, NULLIF(new."*Name_matched", 'No suitable matches found.')
179
			, new."*Name_matched_author"
180
			), '');
181
		accepted_taxon_name_with_author text = NULLIF(concat_ws(' '
182
			, NULLIF(NULLIF(new."*Accepted_name_family", 'Unknown'),
183
				new."*Accepted_name")
184
			, new."*Accepted_name"
185
			, new."*Accepted_name_author"
186
			), '');
187
	BEGIN
188
		new.scrubbed_unique_taxon_name = COALESCE(
189
			accepted_taxon_name_with_author, matched_taxon_name_with_author);
190
	END;
191
	
192
	RETURN new;
193
END;
194
$$;
195

    
196

    
197
--
198
-- Name: FUNCTION taxon_match__fill(); Type: COMMENT; Schema: TNRS; Owner: -
199
--
200

    
201
COMMENT ON FUNCTION taxon_match__fill() IS '
202
IMPORTANT: when changing this function, you must regenerate the derived cols:
203
UPDATE "TNRS".taxon_match SET "Name_submitted" = "Name_submitted"
204
runtime: 30 min ("5564082 rows affected, 1918900 ms execution time")
205
VACUUM ANALYZE "TNRS".taxon_match -- to remove previous rows
206
runtime: 1.5 min ("92633 ms")
207
';
208

    
209

    
210
--
211
-- Name: taxon_match__fill_derived(); Type: FUNCTION; Schema: TNRS; Owner: -
212
--
213

    
214
CREATE FUNCTION taxon_match__fill_derived() RETURNS trigger
215
    LANGUAGE plpgsql
216
    AS $$
217
BEGIN
218
	-- clear derived cols so old values won't be used in calculations
219
	new."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" = NULL;
220
	new."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" = NULL;
221
	new."matched~Name[_no_author]___@TNRS__@vegpath.org" = NULL;
222
	new."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" = NULL;
223
	new.matched_has_accepted = NULL;
224
	new."Accepted_family__@TNRS__@vegpath.org" = NULL;
225
	new."Accepted_species[_binomial]__@TNRS__@vegpath.org" = NULL;
226
	new."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" = NULL;
227
	new."[accepted_]genus__@DwC__@vegpath.org" = NULL;
228
	new."[accepted_]specificEpithet__@DwC__@vegpath.org" = NULL;
229
	new."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" = NULL;
230
	new.__accepted_infraspecific_label = NULL;
231
	new."__accepted_infraspecific_{rank,epithet}" = NULL;
232
	new."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = NULL;
233
	new."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" = NULL;
234
	new."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" = NULL;
235
	new."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" = NULL;
236
	new."[scrubbed_]taxonRank__@DwC__@vegpath.org" = NULL;
237
	new."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" = NULL;
238
	new."[scrubbed_]genus__@DwC__@vegpath.org" = NULL;
239
	new."[scrubbed_]specificEpithet__@DwC__@vegpath.org" = NULL;
240
	new."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" = NULL;
241
	new."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" = NULL;
242
	new."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = NULL;
243
	new."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" = NULL;
244
	new."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" = NULL;
245
	new."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" = NULL;
246
	new."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" = NULL;
247
	
248
	-- populate derived cols
249
	new."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" = (SELECT "*Unmatched_terms" FROM (SELECT new.*) new);
250
	new."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT ("*Genus_matched" || ' '::text) || "*Specific_epithet_matched" FROM (SELECT new.*) new);
251
	new."matched~Name[_no_author]___@TNRS__@vegpath.org" = (SELECT NULLIF("*Name_matched", 'No suitable matches found.'::text) FROM (SELECT new.*) new);
252
	new."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT "matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE((' '::text || "*Name_matched_author"), ''::text) FROM (SELECT new.*) new);
253
	new.matched_has_accepted = (SELECT "*Accepted_name" IS NOT NULL FROM (SELECT new.*) new);
254
	new."Accepted_family__@TNRS__@vegpath.org" = (SELECT COALESCE("*Accepted_name_family",
255
CASE
256
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN "*Accepted_name"
257
    ELSE NULL::text
258
END) FROM (SELECT new.*) new);
259
	new."Accepted_species[_binomial]__@TNRS__@vegpath.org" = (SELECT rtrim("*Accepted_name_species", ' '::text) FROM (SELECT new.*) new);
260
	new."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" = (SELECT regexp_split_to_array("*Accepted_name", ' '::text) FROM (SELECT new.*) new);
261
	new."[accepted_]genus__@DwC__@vegpath.org" = (SELECT "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1] FROM (SELECT new.*) new);
262
	new."[accepted_]specificEpithet__@DwC__@vegpath.org" = (SELECT "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2] FROM (SELECT new.*) new);
263
	new."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" = (SELECT CASE
264
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
265
    WHEN ("*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
266
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
267
END FROM (SELECT new.*) new);
268
	new.__accepted_infraspecific_label = (SELECT ltrim(NULLIF("TNRS".remove_prefix("Accepted_species[_binomial]__@TNRS__@vegpath.org", "*Accepted_name", require := true, case_sensitive := false), ''::text), ' '::text) FROM (SELECT new.*) new);
269
	new."__accepted_infraspecific_{rank,epithet}" = (SELECT regexp_split_to_array(__accepted_infraspecific_label, ' '::text) FROM (SELECT new.*) new);
270
	new."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = (SELECT "__accepted_infraspecific_{rank,epithet}"[1] FROM (SELECT new.*) new);
271
	new."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" = (SELECT "__accepted_infraspecific_{rank,epithet}"[2] FROM (SELECT new.*) new);
272
	new."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT "*Accepted_name" || COALESCE((' '::text || "*Accepted_name_author"), ''::text) FROM (SELECT new.*) new);
273
	new."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" = (SELECT "TNRS".map_taxonomic_status("*Taxonomic_status", "*Accepted_name") FROM (SELECT new.*) new);
274
	new."[scrubbed_]taxonRank__@DwC__@vegpath.org" = (SELECT CASE
275
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
276
    ELSE "*Name_matched_rank"
277
END FROM (SELECT new.*) new);
278
	new."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
279
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
280
    ELSE "*Name_matched_accepted_family"
281
END FROM (SELECT new.*) new);
282
	new."[scrubbed_]genus__@DwC__@vegpath.org" = (SELECT CASE
283
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
284
    ELSE "*Genus_matched"
285
END FROM (SELECT new.*) new);
286
	new."[scrubbed_]specificEpithet__@DwC__@vegpath.org" = (SELECT CASE
287
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
288
    ELSE "*Specific_epithet_matched"
289
END FROM (SELECT new.*) new);
290
	new."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
291
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
292
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
293
END FROM (SELECT new.*) new);
294
	new."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" = (SELECT CASE
295
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'family'::text) THEN concat_ws(' '::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
296
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'genus'::text) THEN concat_ws(' '::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
297
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
298
END FROM (SELECT new.*) new);
299
	new."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = (SELECT CASE
300
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
301
    ELSE "*Infraspecific_rank"
302
END FROM (SELECT new.*) new);
303
	new."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" = (SELECT CASE
304
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
305
    ELSE "*Infraspecific_epithet_matched"
306
END FROM (SELECT new.*) new);
307
	new."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
308
    WHEN matched_has_accepted THEN "*Accepted_name"
309
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
310
END FROM (SELECT new.*) new);
311
	new."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
312
    WHEN matched_has_accepted THEN "*Accepted_name_author"
313
    ELSE "*Name_matched_author"
314
END FROM (SELECT new.*) new);
315
	new."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT CASE
316
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
317
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
318
END FROM (SELECT new.*) new);
319
	
320
	RETURN new;
321
END;
322
$$;
323

    
324

    
325
--
326
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
327
--
328

    
329
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
330
autogenerated, do not edit
331

    
332
to regenerate:
333
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
334
';
335

    
336

    
337
--
338
-- Name: taxon_match__match_num__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
339
--
340

    
341
CREATE FUNCTION taxon_match__match_num__fill() RETURNS trigger
342
    LANGUAGE plpgsql
343
    AS $$
344
BEGIN
345
	IF new.match_num IS NULL THEN
346
		new.match_num = "TNRS".taxon_match__match_num__next();
347
	END IF;
348
	RETURN new;
349
END;
350
$$;
351

    
352

    
353
--
354
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
355
--
356

    
357
CREATE FUNCTION taxon_match__match_num__next() RETURNS bigint
358
    LANGUAGE sql
359
    AS $$
360
SELECT nextval('pg_temp.taxon_match__match_num__seq');
361
$$;
362

    
363

    
364
--
365
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
366
--
367

    
368
CREATE FUNCTION taxon_match_input__copy_to__insert() RETURNS trigger
369
    LANGUAGE plpgsql
370
    AS $$
371
BEGIN
372
	INSERT INTO "TNRS".taxon_match_input SELECT new.*;
373
	RETURN NULL;
374
END;
375
$$;
376

    
377

    
378
--
379
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
380
--
381

    
382
CREATE FUNCTION taxon_name_is_safe(taxon_name text) RETURNS boolean
383
    LANGUAGE sql IMMUTABLE
384
    AS $_$
385
SELECT NOT ($1 = ANY("TNRS".unsafe_taxon_names()))
386
$_$;
387

    
388

    
389
--
390
-- Name: unsafe_taxon_names(); Type: FUNCTION; Schema: TNRS; Owner: -
391
--
392

    
393
CREATE FUNCTION unsafe_taxon_names() RETURNS text[]
394
    LANGUAGE sql IMMUTABLE
395
    AS $$
396
SELECT ARRAY[
397
]::text[]
398
$$;
399

    
400

    
401
SET default_tablespace = '';
402

    
403
SET default_with_oids = false;
404

    
405
--
406
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
407
--
408

    
409
CREATE TABLE taxon_match (
410
    batch text DEFAULT now() NOT NULL,
411
    match_num integer NOT NULL,
412
    "*Name_number" integer NOT NULL,
413
    "*Name_submitted" text NOT NULL,
414
    "*Overall_score" double precision,
415
    "*Name_matched" text,
416
    "*Name_matched_rank" text,
417
    "*Name_score" double precision,
418
    "*Name_matched_author" text,
419
    "*Name_matched_url" text,
420
    "*Author_matched" text,
421
    "*Author_score" double precision,
422
    "*Family_matched" text,
423
    "*Family_score" double precision,
424
    "*Name_matched_accepted_family" text,
425
    "*Genus_matched" text,
426
    "*Genus_score" double precision,
427
    "*Specific_epithet_matched" text,
428
    "*Specific_epithet_score" double precision,
429
    "*Infraspecific_rank" text,
430
    "*Infraspecific_epithet_matched" text,
431
    "*Infraspecific_epithet_score" double precision,
432
    "*Infraspecific_rank_2" text,
433
    "*Infraspecific_epithet_2_matched" text,
434
    "*Infraspecific_epithet_2_score" double precision,
435
    "*Annotations" text,
436
    "*Unmatched_terms" text,
437
    "*Taxonomic_status" text,
438
    "*Accepted_name" text,
439
    "*Accepted_name_author" text,
440
    "*Accepted_name_rank" text,
441
    "*Accepted_name_url" text,
442
    "*Accepted_name_species" text,
443
    "*Accepted_name_family" text,
444
    "*Selected" text,
445
    "*Source" text,
446
    "*Warnings" text,
447
    "*Accepted_name_lsid" text,
448
    is_valid_match boolean NOT NULL,
449
    scrubbed_unique_taxon_name text,
450
    "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" text,
451
    "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" text,
452
    "matched~Name[_no_author]___@TNRS__@vegpath.org" text,
453
    "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" text,
454
    matched_has_accepted boolean,
455
    "Accepted_family__@TNRS__@vegpath.org" text,
456
    "Accepted_species[_binomial]__@TNRS__@vegpath.org" text,
457
    "__accepted_{genus,specific_epithet,infra_{rank,epithet}}" text[],
458
    "[accepted_]genus__@DwC__@vegpath.org" text,
459
    "[accepted_]specificEpithet__@DwC__@vegpath.org" text,
460
    "[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" text,
461
    __accepted_infraspecific_label text,
462
    "__accepted_infraspecific_{rank,epithet}" text[],
463
    "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
464
    "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" text,
465
    "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" text,
466
    "[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" text,
467
    "[scrubbed_]taxonRank__@DwC__@vegpath.org" text,
468
    "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" text,
469
    "[scrubbed_]genus__@DwC__@vegpath.org" text,
470
    "[scrubbed_]specificEpithet__@DwC__@vegpath.org" text,
471
    "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" text,
472
    "[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" text,
473
    "[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
474
    "[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" text,
475
    "[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" text,
476
    "[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" text,
477
    "[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" text,
478
    CONSTRAINT "Accepted_family__@TNRS__@vegpath.org" CHECK ((NOT ("Accepted_family__@TNRS__@vegpath.org" IS DISTINCT FROM COALESCE("*Accepted_name_family",
479
CASE
480
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN "*Accepted_name"
481
    ELSE NULL::text
482
END)))),
483
    CONSTRAINT "Accepted_species[_binomial]__@TNRS__@vegpath.org" CHECK ((NOT ("Accepted_species[_binomial]__@TNRS__@vegpath.org" IS DISTINCT FROM rtrim("*Accepted_name_species", ' '::text)))),
484
    CONSTRAINT "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" CHECK ((NOT ("[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS DISTINCT FROM "__accepted_infraspecific_{rank,epithet}"[1]))),
485
    CONSTRAINT "[accepted_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]genus__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]))),
486
    CONSTRAINT "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_infraspecific_{rank,epithet}"[2]))),
487
    CONSTRAINT "[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" CHECK ((NOT ("[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS DISTINCT FROM
488
CASE
489
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
490
    WHEN ("*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
491
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
492
END))),
493
    CONSTRAINT "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM ("*Accepted_name" || COALESCE((' '::text || "*Accepted_name_author"), ''::text))))),
494
    CONSTRAINT "[accepted_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]))),
495
    CONSTRAINT "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM ("matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE((' '::text || "*Name_matched_author"), ''::text))))),
496
    CONSTRAINT "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM (("*Genus_matched" || ' '::text) || "*Specific_epithet_matched")))),
497
    CONSTRAINT "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" CHECK ((NOT ("[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS DISTINCT FROM "*Unmatched_terms"))),
498
    CONSTRAINT "[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS DISTINCT FROM
499
CASE
500
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
501
    ELSE "*Infraspecific_rank"
502
END))),
503
    CONSTRAINT "[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
504
CASE
505
    WHEN matched_has_accepted THEN "*Accepted_name_author"
506
    ELSE "*Name_matched_author"
507
END))),
508
    CONSTRAINT "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
509
CASE
510
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
511
    ELSE "*Name_matched_accepted_family"
512
END))),
513
    CONSTRAINT "[scrubbed_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]genus__@DwC__@vegpath.org" IS DISTINCT FROM
514
CASE
515
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
516
    ELSE "*Genus_matched"
517
END))),
518
    CONSTRAINT "[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM
519
CASE
520
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
521
    ELSE "*Infraspecific_epithet_matched"
522
END))),
523
    CONSTRAINT "[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" CHECK ((NOT ("[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS DISTINCT FROM
524
CASE
525
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'family'::text) THEN concat_ws(' '::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
526
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'genus'::text) THEN concat_ws(' '::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
527
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
528
END))),
529
    CONSTRAINT "[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
530
CASE
531
    WHEN matched_has_accepted THEN "*Accepted_name"
532
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
533
END))),
534
    CONSTRAINT "[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM
535
CASE
536
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
537
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
538
END))),
539
    CONSTRAINT "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
540
CASE
541
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
542
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
543
END))),
544
    CONSTRAINT "[scrubbed_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM
545
CASE
546
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
547
    ELSE "*Specific_epithet_matched"
548
END))),
549
    CONSTRAINT "[scrubbed_]taxonRank__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]taxonRank__@DwC__@vegpath.org" IS DISTINCT FROM
550
CASE
551
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
552
    ELSE "*Name_matched_rank"
553
END))),
554
    CONSTRAINT "[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" IS DISTINCT FROM map_taxonomic_status("*Taxonomic_status", "*Accepted_name")))),
555
    CONSTRAINT __accepted_infraspecific_label CHECK ((NOT (__accepted_infraspecific_label IS DISTINCT FROM ltrim(NULLIF(remove_prefix("Accepted_species[_binomial]__@TNRS__@vegpath.org", "*Accepted_name", require := true, case_sensitive := false), ''::text), ' '::text)))),
556
    CONSTRAINT "__accepted_infraspecific_{rank,epithet}" CHECK ((NOT ("__accepted_infraspecific_{rank,epithet}" IS DISTINCT FROM regexp_split_to_array(__accepted_infraspecific_label, ' '::text)))),
557
    CONSTRAINT "__accepted_{genus,specific_epithet,infra_{rank,epithet}}" CHECK ((NOT ("__accepted_{genus,specific_epithet,infra_{rank,epithet}}" IS DISTINCT FROM regexp_split_to_array("*Accepted_name", ' '::text)))),
558
    CONSTRAINT matched_has_accepted CHECK ((NOT (matched_has_accepted IS DISTINCT FROM ("*Accepted_name" IS NOT NULL)))),
559
    CONSTRAINT "matched~Name[_no_author]___@TNRS__@vegpath.org" CHECK ((NOT ("matched~Name[_no_author]___@TNRS__@vegpath.org" IS DISTINCT FROM NULLIF("*Name_matched", 'No suitable matches found.'::text))))
560
);
561

    
562

    
563
--
564
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
565
--
566

    
567
COMMENT ON TABLE taxon_match IS '
568
whenever columns are renamed:
569
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
570

    
571
to port derived column changes to vegbiendev:
572
SELECT util.derived_cols_export(''"TNRS".taxon_match'');
573
# run the returned SQL on vegbiendev
574
	-- runtime: 30 min ("5564201 rows affected, 1624829 ms execution time")
575
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
576

    
577
to add a new derived column:
578
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''col''), $$
579
expr
580
$$));
581
SELECT util.derived_cols_populate(''"TNRS".taxon_match'');
582
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
583
$ make schemas/remake
584

    
585
to remove a column:
586
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
587
$ make schemas/remake
588

    
589
to move a derived column to the middle or to add a non-derived column:
590
make the changes in inputs/.TNRS/schema.sql
591
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS; runtime: 1 min ("1m2.629s")
592
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
593
SELECT util.derived_cols_repopulate(''"TNRS".taxon_match'');
594
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
595
$ make schemas/remake
596

    
597
to add a constraint: runtime: 3 min ("173620 ms")
598
';
599

    
600

    
601
--
602
-- Name: COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
603
--
604

    
605
COMMENT ON COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS '
606
= "*Unmatched_terms"
607

    
608
derived column
609

    
610
to modify expr:
611
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org'')::util.col, $$"*Unmatched_terms"$$)::util.derived_col_def);
612
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
613

    
614
to rename:
615
# rename column
616
# rename CHECK constraint
617
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
618
';
619

    
620

    
621
--
622
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
623
--
624

    
625
COMMENT ON COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
626
= ("*Genus_matched" || '' ''::text) || "*Specific_epithet_matched"
627

    
628
derived column
629

    
630
to modify expr:
631
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$("*Genus_matched" || '' ''::text) || "*Specific_epithet_matched"$$)::util.derived_col_def);
632
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
633

    
634
to rename:
635
# rename column
636
# rename CHECK constraint
637
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
638
';
639

    
640

    
641
--
642
-- Name: COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
643
--
644

    
645
COMMENT ON COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org" IS '
646
= NULLIF("*Name_matched", ''No suitable matches found.''::text)
647

    
648
derived column
649

    
650
to modify expr:
651
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched~Name[_no_author]___@TNRS__@vegpath.org'')::util.col, $$NULLIF("*Name_matched", ''No suitable matches found.''::text)$$)::util.derived_col_def);
652
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
653

    
654
to rename:
655
# rename column
656
# rename CHECK constraint
657
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
658
';
659

    
660

    
661
--
662
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
663
--
664

    
665
COMMENT ON COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
666
= "matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)
667

    
668
derived column
669

    
670
to modify expr:
671
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)$$)::util.derived_col_def);
672
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
673

    
674
to rename:
675
# rename column
676
# rename CHECK constraint
677
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
678
';
679

    
680

    
681
--
682
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
683
--
684

    
685
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
686
= "*Accepted_name" IS NOT NULL
687

    
688
derived column
689

    
690
to modify expr:
691
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
692
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
693

    
694
to rename:
695
# rename column
696
# rename CHECK constraint
697
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
698
';
699

    
700

    
701
--
702
-- Name: COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
703
--
704

    
705
COMMENT ON COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org" IS '
706
= COALESCE("*Accepted_name_family",
707
CASE
708
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
709
    ELSE NULL::text
710
END)
711

    
712
derived column
713

    
714
to modify expr:
715
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col, $$COALESCE("*Accepted_name_family",
716
CASE
717
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
718
    ELSE NULL::text
719
END)$$)::util.derived_col_def);
720
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
721

    
722
to rename:
723
# rename column
724
# rename CHECK constraint
725
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
726
';
727

    
728

    
729
--
730
-- Name: COLUMN taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
731
--
732

    
733
COMMENT ON COLUMN taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org" IS '
734
= rtrim("*Accepted_name_species", '' ''::text)
735

    
736
derived column
737

    
738
to modify expr:
739
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_species[_binomial]__@TNRS__@vegpath.org'')::util.col, $$rtrim("*Accepted_name_species", '' ''::text)$$)::util.derived_col_def);
740
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
741

    
742
to rename:
743
# rename column
744
# rename CHECK constraint
745
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
746
';
747

    
748

    
749
--
750
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}"; Type: COMMENT; Schema: TNRS; Owner: -
751
--
752

    
753
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" IS '
754
= regexp_split_to_array("*Accepted_name", '' ''::text)
755

    
756
derived column
757

    
758
to modify expr:
759
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet,infra_{rank,epithet}}'')::util.col, $$regexp_split_to_array("*Accepted_name", '' ''::text)$$)::util.derived_col_def);
760
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
761

    
762
to rename:
763
# rename column
764
# rename CHECK constraint
765
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
766
';
767

    
768

    
769
--
770
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
771
--
772

    
773
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
774
= "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]
775

    
776
derived column
777

    
778
to modify expr:
779
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]$$)::util.derived_col_def);
780
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
781

    
782
to rename:
783
# rename column
784
# rename CHECK constraint
785
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
786
';
787

    
788

    
789
--
790
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
791
--
792

    
793
COMMENT ON COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org" IS '
794
= "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]
795

    
796
derived column
797

    
798
to modify expr:
799
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]$$)::util.derived_col_def);
800
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
801

    
802
to rename:
803
# rename column
804
# rename CHECK constraint
805
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
806
';
807

    
808

    
809
--
810
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
811
--
812

    
813
COMMENT ON COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
814
= CASE
815
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
816
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
817
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
818
END
819

    
820
derived column
821

    
822
to modify expr:
823
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
824
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
825
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
826
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
827
END$$)::util.derived_col_def);
828
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
829

    
830
to rename:
831
# rename column
832
# rename CHECK constraint
833
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
834
';
835

    
836

    
837
--
838
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
839
--
840

    
841
COMMENT ON COLUMN taxon_match.__accepted_infraspecific_label IS '
842
= ltrim(NULLIF("TNRS".remove_prefix("Accepted_species[_binomial]__@TNRS__@vegpath.org", "*Accepted_name", require := true, case_sensitive := false), ''''::text), '' ''::text)
843

    
844
derived column
845

    
846
to modify expr:
847
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_label'')::util.col, $$ltrim(NULLIF("TNRS".remove_prefix("Accepted_species[_binomial]__@TNRS__@vegpath.org", "*Accepted_name", require := true, case_sensitive := false), ''''::text), '' ''::text)$$)::util.derived_col_def);
848
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
849

    
850
to rename:
851
# rename column
852
# rename CHECK constraint
853
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
854
';
855

    
856

    
857
--
858
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
859
--
860

    
861
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
862
= regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
863

    
864
derived column
865

    
866
to modify expr:
867
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col, $$regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)$$)::util.derived_col_def);
868
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
869

    
870
to rename:
871
# rename column
872
# rename CHECK constraint
873
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
874
';
875

    
876

    
877
--
878
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
879
--
880

    
881
COMMENT ON COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
882
= "__accepted_infraspecific_{rank,epithet}"[1]
883

    
884
derived column
885

    
886
to modify expr:
887
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$"__accepted_infraspecific_{rank,epithet}"[1]$$)::util.derived_col_def);
888
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
889

    
890
to rename:
891
# rename column
892
# rename CHECK constraint
893
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
894
';
895

    
896

    
897
--
898
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
899
--
900

    
901
COMMENT ON COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS '
902
= "__accepted_infraspecific_{rank,epithet}"[2]
903

    
904
derived column
905

    
906
to modify expr:
907
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_infraspecific_{rank,epithet}"[2]$$)::util.derived_col_def);
908
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
909

    
910
to rename:
911
# rename column
912
# rename CHECK constraint
913
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
914
';
915

    
916

    
917
--
918
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
919
--
920

    
921
COMMENT ON COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
922
= "*Accepted_name" || COALESCE(('' ''::text || "*Accepted_name_author"), ''''::text)
923

    
924
derived column
925

    
926
to modify expr:
927
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"*Accepted_name" || COALESCE(('' ''::text || "*Accepted_name_author"), ''''::text)$$)::util.derived_col_def);
928
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
929

    
930
to rename:
931
# rename column
932
# rename CHECK constraint
933
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
934
';
935

    
936

    
937
--
938
-- Name: COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
939
--
940

    
941
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" IS '
942
= "TNRS".map_taxonomic_status("*Taxonomic_status", "*Accepted_name")
943

    
944
derived column
945

    
946
to modify expr:
947
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonomicStatus__@DwC__@vegpath.org'')::util.col, $$"TNRS".map_taxonomic_status("*Taxonomic_status", "*Accepted_name")$$)::util.derived_col_def);
948
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
949

    
950
to rename:
951
# rename column
952
# rename CHECK constraint
953
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
954
';
955

    
956

    
957
--
958
-- Name: COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
959
--
960

    
961
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
962
= CASE
963
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
964
    ELSE "*Name_matched_rank"
965
END
966

    
967
derived column
968

    
969
to modify expr:
970
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
971
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
972
    ELSE "*Name_matched_rank"
973
END$$)::util.derived_col_def);
974
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
975

    
976
to rename:
977
# rename column
978
# rename CHECK constraint
979
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
980
';
981

    
982

    
983
--
984
-- Name: COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
985
--
986

    
987
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
988
= CASE
989
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
990
    ELSE "*Name_matched_accepted_family"
991
END
992

    
993
derived column
994

    
995
to modify expr:
996
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
997
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
998
    ELSE "*Name_matched_accepted_family"
999
END$$)::util.derived_col_def);
1000
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1001

    
1002
to rename:
1003
# rename column
1004
# rename CHECK constraint
1005
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1006
';
1007

    
1008

    
1009
--
1010
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1011
--
1012

    
1013
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
1014
= CASE
1015
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1016
    ELSE "*Genus_matched"
1017
END
1018

    
1019
derived column
1020

    
1021
to modify expr:
1022
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
1023
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1024
    ELSE "*Genus_matched"
1025
END$$)::util.derived_col_def);
1026
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1027

    
1028
to rename:
1029
# rename column
1030
# rename CHECK constraint
1031
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1032
';
1033

    
1034

    
1035
--
1036
-- Name: COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1037
--
1038

    
1039
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
1040
= CASE
1041
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1042
    ELSE "*Specific_epithet_matched"
1043
END
1044

    
1045
derived column
1046

    
1047
to modify expr:
1048
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1049
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1050
    ELSE "*Specific_epithet_matched"
1051
END$$)::util.derived_col_def);
1052
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1053

    
1054
to rename:
1055
# rename column
1056
# rename CHECK constraint
1057
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1058
';
1059

    
1060

    
1061
--
1062
-- Name: COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1063
--
1064

    
1065
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1066
= CASE
1067
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1068
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1069
END
1070

    
1071
derived column
1072

    
1073
to modify expr:
1074
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1075
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1076
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1077
END$$)::util.derived_col_def);
1078
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1079

    
1080
to rename:
1081
# rename column
1082
# rename CHECK constraint
1083
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1084
';
1085

    
1086

    
1087
--
1088
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1089
--
1090

    
1091
COMMENT ON COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
1092
= CASE
1093
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''family''::text) THEN concat_ws('' ''::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1094
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1095
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1096
END
1097

    
1098
derived column
1099

    
1100
to modify expr:
1101
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
1102
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''family''::text) THEN concat_ws('' ''::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1103
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1104
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1105
END$$)::util.derived_col_def);
1106
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1107

    
1108
to rename:
1109
# rename column
1110
# rename CHECK constraint
1111
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1112
';
1113

    
1114

    
1115
--
1116
-- Name: COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1117
--
1118

    
1119
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1120
= CASE
1121
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1122
    ELSE "*Infraspecific_rank"
1123
END
1124

    
1125
derived column
1126

    
1127
to modify expr:
1128
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$CASE
1129
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1130
    ELSE "*Infraspecific_rank"
1131
END$$)::util.derived_col_def);
1132
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1133

    
1134
to rename:
1135
# rename column
1136
# rename CHECK constraint
1137
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1138
';
1139

    
1140

    
1141
--
1142
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1143
--
1144

    
1145
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1146
= CASE
1147
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1148
    ELSE "*Infraspecific_epithet_matched"
1149
END
1150

    
1151
derived column
1152

    
1153
to modify expr:
1154
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1155
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1156
    ELSE "*Infraspecific_epithet_matched"
1157
END$$)::util.derived_col_def);
1158
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1159

    
1160
to rename:
1161
# rename column
1162
# rename CHECK constraint
1163
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1164
';
1165

    
1166

    
1167
--
1168
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1169
--
1170

    
1171
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1172
= CASE
1173
    WHEN matched_has_accepted THEN "*Accepted_name"
1174
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1175
END
1176

    
1177
derived column
1178

    
1179
to modify expr:
1180
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1181
    WHEN matched_has_accepted THEN "*Accepted_name"
1182
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1183
END$$)::util.derived_col_def);
1184
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1185

    
1186
to rename:
1187
# rename column
1188
# rename CHECK constraint
1189
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1190
';
1191

    
1192

    
1193
--
1194
-- Name: COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1195
--
1196

    
1197
COMMENT ON COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1198
= CASE
1199
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1200
    ELSE "*Name_matched_author"
1201
END
1202

    
1203
derived column
1204

    
1205
to modify expr:
1206
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1207
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1208
    ELSE "*Name_matched_author"
1209
END$$)::util.derived_col_def);
1210
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1211

    
1212
to rename:
1213
# rename column
1214
# rename CHECK constraint
1215
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1216
';
1217

    
1218

    
1219
--
1220
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1221
--
1222

    
1223
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1224
= CASE
1225
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1226
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1227
END
1228

    
1229
derived column
1230

    
1231
to modify expr:
1232
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$CASE
1233
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1234
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1235
END$$)::util.derived_col_def);
1236
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1237

    
1238
to rename:
1239
# rename column
1240
# rename CHECK constraint
1241
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1242
';
1243

    
1244

    
1245
--
1246
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1247
--
1248

    
1249
CREATE VIEW taxon_best_match AS
1250
 SELECT taxon_match.batch,
1251
    taxon_match.match_num,
1252
    taxon_match."*Name_number",
1253
    taxon_match."*Name_submitted",
1254
    taxon_match."*Overall_score",
1255
    taxon_match."*Name_matched",
1256
    taxon_match."*Name_matched_rank",
1257
    taxon_match."*Name_score",
1258
    taxon_match."*Name_matched_author",
1259
    taxon_match."*Name_matched_url",
1260
    taxon_match."*Author_matched",
1261
    taxon_match."*Author_score",
1262
    taxon_match."*Family_matched",
1263
    taxon_match."*Family_score",
1264
    taxon_match."*Name_matched_accepted_family",
1265
    taxon_match."*Genus_matched",
1266
    taxon_match."*Genus_score",
1267
    taxon_match."*Specific_epithet_matched",
1268
    taxon_match."*Specific_epithet_score",
1269
    taxon_match."*Infraspecific_rank",
1270
    taxon_match."*Infraspecific_epithet_matched",
1271
    taxon_match."*Infraspecific_epithet_score",
1272
    taxon_match."*Infraspecific_rank_2",
1273
    taxon_match."*Infraspecific_epithet_2_matched",
1274
    taxon_match."*Infraspecific_epithet_2_score",
1275
    taxon_match."*Annotations",
1276
    taxon_match."*Unmatched_terms",
1277
    taxon_match."*Taxonomic_status",
1278
    taxon_match."*Accepted_name",
1279
    taxon_match."*Accepted_name_author",
1280
    taxon_match."*Accepted_name_rank",
1281
    taxon_match."*Accepted_name_url",
1282
    taxon_match."*Accepted_name_species",
1283
    taxon_match."*Accepted_name_family",
1284
    taxon_match."*Selected",
1285
    taxon_match."*Source",
1286
    taxon_match."*Warnings",
1287
    taxon_match."*Accepted_name_lsid",
1288
    taxon_match.is_valid_match,
1289
    taxon_match.scrubbed_unique_taxon_name,
1290
    taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1291
    taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1292
    taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org",
1293
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1294
    taxon_match.matched_has_accepted,
1295
    taxon_match."Accepted_family__@TNRS__@vegpath.org",
1296
    taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1297
    taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" AS "__accepted_{genus,specific_epithet}",
1298
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
1299
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1300
    taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1301
    taxon_match.__accepted_infraspecific_label,
1302
    taxon_match."__accepted_infraspecific_{rank,epithet}",
1303
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1304
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1305
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1306
    taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1307
    taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1308
    taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1309
    taxon_match."[scrubbed_]genus__@DwC__@vegpath.org",
1310
    taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1311
    taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1312
    taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1313
    taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1314
    taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1315
    taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1316
    taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1317
    taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1318
   FROM taxon_match
1319
  WHERE (taxon_match."*Selected" = 'true'::text);
1320

    
1321

    
1322
--
1323
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1324
--
1325

    
1326
COMMENT ON VIEW taxon_best_match IS '
1327
to modify:
1328
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1329
SELECT __
1330
$$);
1331
';
1332

    
1333

    
1334
--
1335
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1336
--
1337

    
1338
CREATE VIEW "MatchedTaxon" AS
1339
 SELECT taxon_best_match.batch,
1340
    taxon_best_match.match_num,
1341
    taxon_best_match."*Name_number",
1342
    taxon_best_match."*Name_submitted",
1343
    taxon_best_match."*Overall_score",
1344
    taxon_best_match."*Name_matched",
1345
    taxon_best_match."*Name_matched_rank",
1346
    taxon_best_match."*Name_score",
1347
    taxon_best_match."*Name_matched_author",
1348
    taxon_best_match."*Name_matched_url",
1349
    taxon_best_match."*Author_matched",
1350
    taxon_best_match."*Author_score",
1351
    taxon_best_match."*Family_matched",
1352
    taxon_best_match."*Family_score",
1353
    taxon_best_match."*Name_matched_accepted_family",
1354
    taxon_best_match."*Genus_matched",
1355
    taxon_best_match."*Genus_score",
1356
    taxon_best_match."*Specific_epithet_matched",
1357
    taxon_best_match."*Specific_epithet_score",
1358
    taxon_best_match."*Infraspecific_rank",
1359
    taxon_best_match."*Infraspecific_epithet_matched",
1360
    taxon_best_match."*Infraspecific_epithet_score",
1361
    taxon_best_match."*Infraspecific_rank_2",
1362
    taxon_best_match."*Infraspecific_epithet_2_matched",
1363
    taxon_best_match."*Infraspecific_epithet_2_score",
1364
    taxon_best_match."*Annotations",
1365
    taxon_best_match."*Unmatched_terms",
1366
    taxon_best_match."*Taxonomic_status",
1367
    taxon_best_match."*Accepted_name",
1368
    taxon_best_match."*Accepted_name_author",
1369
    taxon_best_match."*Accepted_name_rank",
1370
    taxon_best_match."*Accepted_name_url",
1371
    taxon_best_match."*Accepted_name_species",
1372
    taxon_best_match."*Accepted_name_family",
1373
    taxon_best_match."*Selected",
1374
    taxon_best_match."*Source",
1375
    taxon_best_match."*Warnings",
1376
    taxon_best_match."*Accepted_name_lsid",
1377
    taxon_best_match.is_valid_match,
1378
    taxon_best_match.scrubbed_unique_taxon_name,
1379
    taxon_best_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1380
    taxon_best_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1381
    taxon_best_match."matched~Name[_no_author]___@TNRS__@vegpath.org",
1382
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1383
    taxon_best_match.matched_has_accepted,
1384
    taxon_best_match."Accepted_family__@TNRS__@vegpath.org",
1385
    taxon_best_match."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1386
    taxon_best_match."__accepted_{genus,specific_epithet}",
1387
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
1388
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1389
    taxon_best_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1390
    taxon_best_match.__accepted_infraspecific_label,
1391
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
1392
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1393
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1394
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1395
    taxon_best_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1396
    taxon_best_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1397
    taxon_best_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1398
    taxon_best_match."[scrubbed_]genus__@DwC__@vegpath.org",
1399
    taxon_best_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1400
    taxon_best_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1401
    taxon_best_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1402
    taxon_best_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1403
    taxon_best_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1404
    taxon_best_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1405
    taxon_best_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1406
    taxon_best_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1407
    map_taxonomic_status(taxon_best_match."*Taxonomic_status", taxon_best_match."*Accepted_name") AS "taxonomicStatus",
1408
        CASE
1409
            WHEN (taxon_best_match."*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name_family", taxon_best_match."*Unmatched_terms")
1410
            WHEN (taxon_best_match."*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name", taxon_best_match."*Unmatched_terms")
1411
            ELSE taxon_best_match."*Accepted_name_species"
1412
        END AS accepted_morphospecies_binomial
1413
   FROM taxon_best_match;
1414

    
1415

    
1416
--
1417
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1418
--
1419

    
1420
COMMENT ON VIEW "MatchedTaxon" IS '
1421
to modify:
1422
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
1423
SELECT __
1424
$$);
1425
';
1426

    
1427

    
1428
--
1429
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1430
--
1431

    
1432
CREATE VIEW "ValidMatchedTaxon" AS
1433
 SELECT "MatchedTaxon".batch,
1434
    "MatchedTaxon".match_num,
1435
    "MatchedTaxon"."*Name_number",
1436
    "MatchedTaxon"."*Name_submitted",
1437
    "MatchedTaxon"."*Overall_score",
1438
    "MatchedTaxon"."*Name_matched",
1439
    "MatchedTaxon"."*Name_matched_rank",
1440
    "MatchedTaxon"."*Name_score",
1441
    "MatchedTaxon"."*Name_matched_author",
1442
    "MatchedTaxon"."*Name_matched_url",
1443
    "MatchedTaxon"."*Author_matched",
1444
    "MatchedTaxon"."*Author_score",
1445
    "MatchedTaxon"."*Family_matched",
1446
    "MatchedTaxon"."*Family_score",
1447
    "MatchedTaxon"."*Name_matched_accepted_family",
1448
    "MatchedTaxon"."*Genus_matched",
1449
    "MatchedTaxon"."*Genus_score",
1450
    "MatchedTaxon"."*Specific_epithet_matched",
1451
    "MatchedTaxon"."*Specific_epithet_score",
1452
    "MatchedTaxon"."*Infraspecific_rank",
1453
    "MatchedTaxon"."*Infraspecific_epithet_matched",
1454
    "MatchedTaxon"."*Infraspecific_epithet_score",
1455
    "MatchedTaxon"."*Infraspecific_rank_2",
1456
    "MatchedTaxon"."*Infraspecific_epithet_2_matched",
1457
    "MatchedTaxon"."*Infraspecific_epithet_2_score",
1458
    "MatchedTaxon"."*Annotations",
1459
    "MatchedTaxon"."*Unmatched_terms",
1460
    "MatchedTaxon"."*Taxonomic_status",
1461
    "MatchedTaxon"."*Accepted_name",
1462
    "MatchedTaxon"."*Accepted_name_author",
1463
    "MatchedTaxon"."*Accepted_name_rank",
1464
    "MatchedTaxon"."*Accepted_name_url",
1465
    "MatchedTaxon"."*Accepted_name_species",
1466
    "MatchedTaxon"."*Accepted_name_family",
1467
    "MatchedTaxon"."*Selected",
1468
    "MatchedTaxon"."*Source",
1469
    "MatchedTaxon"."*Warnings",
1470
    "MatchedTaxon"."*Accepted_name_lsid",
1471
    "MatchedTaxon".is_valid_match,
1472
    "MatchedTaxon".scrubbed_unique_taxon_name,
1473
    "MatchedTaxon"."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1474
    "MatchedTaxon"."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1475
    "MatchedTaxon"."matched~Name[_no_author]___@TNRS__@vegpath.org",
1476
    "MatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1477
    "MatchedTaxon".matched_has_accepted,
1478
    "MatchedTaxon"."Accepted_family__@TNRS__@vegpath.org",
1479
    "MatchedTaxon"."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1480
    "MatchedTaxon"."__accepted_{genus,specific_epithet}",
1481
    "MatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1482
    "MatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1483
    "MatchedTaxon"."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1484
    "MatchedTaxon".__accepted_infraspecific_label,
1485
    "MatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1486
    "MatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1487
    "MatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1488
    "MatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1489
    "MatchedTaxon"."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1490
    "MatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1491
    "MatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1492
    "MatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org",
1493
    "MatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1494
    "MatchedTaxon"."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1495
    "MatchedTaxon"."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1496
    "MatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1497
    "MatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1498
    "MatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1499
    "MatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1500
    "MatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1501
    "MatchedTaxon"."taxonomicStatus",
1502
    "MatchedTaxon".accepted_morphospecies_binomial
1503
   FROM "MatchedTaxon"
1504
  WHERE "MatchedTaxon".is_valid_match;
1505

    
1506

    
1507
--
1508
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1509
--
1510

    
1511
COMMENT ON VIEW "ValidMatchedTaxon" IS '
1512
to update, use * as the column list
1513
';
1514

    
1515

    
1516
--
1517
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1518
--
1519

    
1520
CREATE TABLE batch (
1521
    id text NOT NULL,
1522
    id_by_time text,
1523
    time_submitted timestamp with time zone DEFAULT now(),
1524
    client_version text
1525
);
1526

    
1527

    
1528
--
1529
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1530
--
1531

    
1532
CREATE TABLE batch_download_settings (
1533
    id text NOT NULL,
1534
    "E-mail" text,
1535
    "Id" text,
1536
    "Job type" text,
1537
    "Contains Id" boolean,
1538
    "Start time" text,
1539
    "Finish time" text,
1540
    "TNRS version" text,
1541
    "Sources selected" text,
1542
    "Match threshold" double precision,
1543
    "Classification" text,
1544
    "Allow partial matches?" boolean,
1545
    "Sort by source" boolean,
1546
    "Constrain by higher taxonomy" boolean
1547
);
1548

    
1549

    
1550
--
1551
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
1552
--
1553

    
1554
COMMENT ON TABLE batch_download_settings IS '
1555
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
1556
';
1557

    
1558

    
1559
--
1560
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1561
--
1562

    
1563
CREATE TABLE client_version (
1564
    id text NOT NULL,
1565
    global_rev integer NOT NULL,
1566
    "/lib/tnrs.py rev" integer,
1567
    "/bin/tnrs_db rev" integer
1568
);
1569

    
1570

    
1571
--
1572
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
1573
--
1574

    
1575
COMMENT ON TABLE client_version IS '
1576
contains svn revisions
1577
';
1578

    
1579

    
1580
--
1581
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
1582
--
1583

    
1584
COMMENT ON COLUMN client_version.global_rev IS '
1585
from `svn info .` > Last Changed Rev
1586
';
1587

    
1588

    
1589
--
1590
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
1591
--
1592

    
1593
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
1594
from `svn info lib/tnrs.py` > Last Changed Rev
1595
';
1596

    
1597

    
1598
--
1599
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
1600
--
1601

    
1602
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
1603
from `svn info bin/tnrs_db` > Last Changed Rev
1604
';
1605

    
1606

    
1607
--
1608
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1609
--
1610

    
1611
CREATE VIEW taxon_match_input AS
1612
 SELECT taxon_match."*Name_number" AS "Name_number",
1613
    taxon_match."*Name_submitted" AS "Name_submitted",
1614
    taxon_match."*Overall_score" AS "Overall_score",
1615
    taxon_match."*Name_matched" AS "Name_matched",
1616
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1617
    taxon_match."*Name_score" AS "Name_score",
1618
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1619
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1620
    taxon_match."*Author_matched" AS "Author_matched",
1621
    taxon_match."*Author_score" AS "Author_score",
1622
    taxon_match."*Family_matched" AS "Family_matched",
1623
    taxon_match."*Family_score" AS "Family_score",
1624
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1625
    taxon_match."*Genus_matched" AS "Genus_matched",
1626
    taxon_match."*Genus_score" AS "Genus_score",
1627
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1628
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1629
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1630
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1631
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1632
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1633
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1634
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1635
    taxon_match."*Annotations" AS "Annotations",
1636
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1637
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1638
    taxon_match."*Accepted_name" AS "Accepted_name",
1639
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1640
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1641
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1642
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1643
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1644
    taxon_match."*Selected" AS "Selected",
1645
    taxon_match."*Source" AS "Source",
1646
    taxon_match."*Warnings" AS "Warnings",
1647
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1648
   FROM taxon_match;
1649

    
1650

    
1651
--
1652
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1653
--
1654

    
1655
CREATE TABLE taxon_match_input__copy_to (
1656
    "Name_number" integer,
1657
    "Name_submitted" text,
1658
    "Overall_score" double precision,
1659
    "Name_matched" text,
1660
    "Name_matched_rank" text,
1661
    "Name_score" double precision,
1662
    "Name_matched_author" text,
1663
    "Name_matched_url" text,
1664
    "Author_matched" text,
1665
    "Author_score" double precision,
1666
    "Family_matched" text,
1667
    "Family_score" double precision,
1668
    "Name_matched_accepted_family" text,
1669
    "Genus_matched" text,
1670
    "Genus_score" double precision,
1671
    "Specific_epithet_matched" text,
1672
    "Specific_epithet_score" double precision,
1673
    "Infraspecific_rank" text,
1674
    "Infraspecific_epithet_matched" text,
1675
    "Infraspecific_epithet_score" double precision,
1676
    "Infraspecific_rank_2" text,
1677
    "Infraspecific_epithet_2_matched" text,
1678
    "Infraspecific_epithet_2_score" double precision,
1679
    "Annotations" text,
1680
    "Unmatched_terms" text,
1681
    "Taxonomic_status" text,
1682
    "Accepted_name" text,
1683
    "Accepted_name_author" text,
1684
    "Accepted_name_rank" text,
1685
    "Accepted_name_url" text,
1686
    "Accepted_name_species" text,
1687
    "Accepted_name_family" text,
1688
    "Selected" text,
1689
    "Source" text,
1690
    "Warnings" text,
1691
    "Accepted_name_lsid" text
1692
);
1693

    
1694

    
1695
--
1696
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
1697
--
1698

    
1699
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
1700
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
1701
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
1702
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
1703
    taxon_match."*Genus_matched" AS scrubbed_genus,
1704
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
1705
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
1706
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
1707
    taxon_match."*Name_matched_author" AS scrubbed_author,
1708
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
1709
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
1710
   FROM taxon_match;
1711

    
1712

    
1713
--
1714
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1715
--
1716

    
1717
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1718
to modify:
1719
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1720
SELECT __
1721
$$);
1722

    
1723
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.
1724
';
1725

    
1726

    
1727
--
1728
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1729
--
1730

    
1731
CREATE VIEW taxon_scrub AS
1732
 SELECT "ValidMatchedTaxon".scrubbed_unique_taxon_name,
1733
    "ValidMatchedTaxon".batch,
1734
    "ValidMatchedTaxon".match_num,
1735
    "ValidMatchedTaxon"."*Name_number",
1736
    "ValidMatchedTaxon"."*Name_submitted",
1737
    "ValidMatchedTaxon"."*Overall_score",
1738
    "ValidMatchedTaxon"."*Name_matched",
1739
    "ValidMatchedTaxon"."*Name_matched_rank",
1740
    "ValidMatchedTaxon"."*Name_score",
1741
    "ValidMatchedTaxon"."*Name_matched_author",
1742
    "ValidMatchedTaxon"."*Name_matched_url",
1743
    "ValidMatchedTaxon"."*Author_matched",
1744
    "ValidMatchedTaxon"."*Author_score",
1745
    "ValidMatchedTaxon"."*Family_matched",
1746
    "ValidMatchedTaxon"."*Family_score",
1747
    "ValidMatchedTaxon"."*Name_matched_accepted_family",
1748
    "ValidMatchedTaxon"."*Genus_matched",
1749
    "ValidMatchedTaxon"."*Genus_score",
1750
    "ValidMatchedTaxon"."*Specific_epithet_matched",
1751
    "ValidMatchedTaxon"."*Specific_epithet_score",
1752
    "ValidMatchedTaxon"."*Infraspecific_rank",
1753
    "ValidMatchedTaxon"."*Infraspecific_epithet_matched",
1754
    "ValidMatchedTaxon"."*Infraspecific_epithet_score",
1755
    "ValidMatchedTaxon"."*Infraspecific_rank_2",
1756
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_matched",
1757
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_score",
1758
    "ValidMatchedTaxon"."*Annotations",
1759
    "ValidMatchedTaxon"."*Unmatched_terms",
1760
    "ValidMatchedTaxon"."*Taxonomic_status",
1761
    "ValidMatchedTaxon"."*Accepted_name",
1762
    "ValidMatchedTaxon"."*Accepted_name_author",
1763
    "ValidMatchedTaxon"."*Accepted_name_rank",
1764
    "ValidMatchedTaxon"."*Accepted_name_url",
1765
    "ValidMatchedTaxon"."*Accepted_name_species",
1766
    "ValidMatchedTaxon"."*Accepted_name_family",
1767
    "ValidMatchedTaxon"."*Selected",
1768
    "ValidMatchedTaxon"."*Source",
1769
    "ValidMatchedTaxon"."*Warnings",
1770
    "ValidMatchedTaxon"."*Accepted_name_lsid",
1771
    "ValidMatchedTaxon".is_valid_match,
1772
    "ValidMatchedTaxon"."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1773
    "ValidMatchedTaxon"."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1774
    "ValidMatchedTaxon"."matched~Name[_no_author]___@TNRS__@vegpath.org",
1775
    "ValidMatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1776
    "ValidMatchedTaxon".matched_has_accepted,
1777
    "ValidMatchedTaxon"."Accepted_family__@TNRS__@vegpath.org",
1778
    "ValidMatchedTaxon"."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1779
    "ValidMatchedTaxon"."__accepted_{genus,specific_epithet}",
1780
    "ValidMatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1781
    "ValidMatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1782
    "ValidMatchedTaxon"."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1783
    "ValidMatchedTaxon".__accepted_infraspecific_label,
1784
    "ValidMatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1785
    "ValidMatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1786
    "ValidMatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1787
    "ValidMatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1788
    "ValidMatchedTaxon"."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1789
    "ValidMatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1790
    "ValidMatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1791
    "ValidMatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org",
1792
    "ValidMatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1793
    "ValidMatchedTaxon"."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1794
    "ValidMatchedTaxon"."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1795
    "ValidMatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1796
    "ValidMatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1797
    "ValidMatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1798
    "ValidMatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1799
    "ValidMatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1800
    "ValidMatchedTaxon"."taxonomicStatus",
1801
    "ValidMatchedTaxon".accepted_morphospecies_binomial,
1802
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank,
1803
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family,
1804
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus,
1805
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet,
1806
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_rank,
1807
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_epithet,
1808
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_author,
1809
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author,
1810
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_with_author,
1811
        CASE
1812
            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"."*Unmatched_terms")
1813
            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"."*Unmatched_terms")
1814
            ELSE (("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus || ' '::text) || "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet)
1815
        END AS scrubbed_morphospecies_binomial
1816
   FROM ("ValidMatchedTaxon"
1817
   LEFT JOIN "taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name));
1818

    
1819

    
1820
--
1821
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1822
--
1823

    
1824
COMMENT ON VIEW taxon_scrub IS '
1825
to modify:
1826
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1827
SELECT __
1828
$$);
1829
';
1830

    
1831

    
1832
--
1833
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1834
--
1835

    
1836
ALTER TABLE ONLY batch_download_settings
1837
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1838

    
1839

    
1840
--
1841
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1842
--
1843

    
1844
ALTER TABLE ONLY batch
1845
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1846

    
1847

    
1848
--
1849
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1850
--
1851

    
1852
ALTER TABLE ONLY batch
1853
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1854

    
1855

    
1856
--
1857
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1858
--
1859

    
1860
ALTER TABLE ONLY client_version
1861
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1862

    
1863

    
1864
--
1865
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1866
--
1867

    
1868
ALTER TABLE ONLY taxon_match
1869
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1870

    
1871
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1872

    
1873

    
1874
--
1875
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1876
--
1877

    
1878
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1879

    
1880

    
1881
--
1882
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1883
--
1884

    
1885
CREATE INDEX taxon_best_match__valid_match ON taxon_match USING btree ("*Name_submitted") WHERE (("*Selected" = 'true'::text) AND is_valid_match);
1886

    
1887

    
1888
--
1889
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1890
--
1891

    
1892
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1893

    
1894

    
1895
--
1896
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1897
--
1898

    
1899
CREATE UNIQUE INDEX taxon_match__one_selected_match ON taxon_match USING btree (batch, "*Name_number") WHERE ("*Selected" = 'true'::text);
1900

    
1901

    
1902
--
1903
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1904
--
1905

    
1906
CREATE TRIGGER batch__fill BEFORE INSERT OR UPDATE ON batch FOR EACH ROW EXECUTE PROCEDURE batch__fill();
1907

    
1908

    
1909
--
1910
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1911
--
1912

    
1913
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1914

    
1915

    
1916
--
1917
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1918
--
1919

    
1920
CREATE TRIGGER taxon_match__fill BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill();
1921

    
1922

    
1923
--
1924
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1925
--
1926

    
1927
CREATE TRIGGER taxon_match__fill_derived BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill_derived();
1928

    
1929

    
1930
--
1931
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1932
--
1933

    
1934
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1935

    
1936

    
1937
--
1938
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1939
--
1940

    
1941
CREATE TRIGGER taxon_match_input__copy_to__insert BEFORE INSERT ON taxon_match_input__copy_to FOR EACH ROW EXECUTE PROCEDURE taxon_match_input__copy_to__insert();
1942

    
1943

    
1944
--
1945
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1946
--
1947

    
1948
ALTER TABLE ONLY batch
1949
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1950

    
1951

    
1952
--
1953
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1954
--
1955

    
1956
ALTER TABLE ONLY batch_download_settings
1957
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1958

    
1959

    
1960
--
1961
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1962
--
1963

    
1964
ALTER TABLE ONLY taxon_match
1965
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1966

    
1967

    
1968
--
1969
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1970
--
1971

    
1972
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1973
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1974
GRANT ALL ON SCHEMA "TNRS" TO bien;
1975
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1976

    
1977

    
1978
--
1979
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1980
--
1981

    
1982
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1983
REVOKE ALL ON TABLE taxon_match FROM bien;
1984
GRANT ALL ON TABLE taxon_match TO bien;
1985
GRANT SELECT ON TABLE taxon_match TO bien_read;
1986

    
1987

    
1988
--
1989
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1990
--
1991

    
1992
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1993
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1994
GRANT ALL ON TABLE taxon_best_match TO bien;
1995
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1996

    
1997

    
1998
--
1999
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
2000
--
2001

    
2002
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
2003
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
2004
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
2005
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
2006

    
2007

    
2008
--
2009
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
2010
--
2011

    
2012
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
2013
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
2014
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
2015
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
2016

    
2017

    
2018
--
2019
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
2020
--
2021

    
2022
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
2023
REVOKE ALL ON TABLE taxon_match_input FROM bien;
2024
GRANT ALL ON TABLE taxon_match_input TO bien;
2025
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
2026

    
2027

    
2028
--
2029
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
2030
--
2031

    
2032
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
2033
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
2034
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
2035
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
2036

    
2037

    
2038
--
2039
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
2040
--
2041

    
2042
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
2043
REVOKE ALL ON TABLE taxon_scrub FROM bien;
2044
GRANT ALL ON TABLE taxon_scrub TO bien;
2045
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
2046

    
2047

    
2048
--
2049
-- PostgreSQL database dump complete
2050
--
2051

    
(7-7/9)