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

    
326

    
327
--
328
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
329
--
330

    
331
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
332
autogenerated, do not edit
333

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

    
338

    
339
--
340
-- Name: taxon_match__match_num__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
341
--
342

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

    
354

    
355
--
356
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
357
--
358

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

    
365

    
366
--
367
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
368
--
369

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

    
379

    
380
--
381
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
382
--
383

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

    
390

    
391
--
392
-- Name: unsafe_taxon_names(); Type: FUNCTION; Schema: TNRS; Owner: -
393
--
394

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

    
402

    
403
SET default_tablespace = '';
404

    
405
SET default_with_oids = false;
406

    
407
--
408
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
409
--
410

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

    
566

    
567
--
568
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
569
--
570

    
571
COMMENT ON TABLE taxon_match IS '
572
whenever columns are renamed:
573
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
574

    
575
to port derived column changes to vegbiendev:
576
SELECT util.derived_cols_export(''"TNRS".taxon_match'');
577
# run the returned SQL on vegbiendev
578
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
579

    
580
to remove columns or add columns at the end:
581
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
582
$ make schemas/remake
583

    
584
to add columns in the middle:
585
make the changes in inputs/.TNRS/schema.sql
586
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS
587
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
588
SELECT util.derived_cols_repopulate(''"TNRS".taxon_match'');
589
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
590
$ make schemas/remake
591

    
592
to add a new derived column:
593
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''col''), $$
594
expr
595
$$));
596
SELECT util.derived_cols_populate(''"TNRS".taxon_match'');
597
	-- runtime: 30 min ("5564201 rows affected, 1624829 ms execution time")
598

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

    
602

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

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

    
610
derived column
611

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

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

    
622

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

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

    
630
derived column
631

    
632
to modify expr:
633
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);
634
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
635

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

    
642

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

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

    
650
derived column
651

    
652
to modify expr:
653
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);
654
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
655

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

    
662

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

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

    
670
derived column
671

    
672
to modify expr:
673
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);
674
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
675

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

    
682

    
683
--
684
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
685
--
686

    
687
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
688
= "*Accepted_name" IS NOT NULL
689

    
690
derived column
691

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

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

    
702

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

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

    
714
derived column
715

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

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

    
730

    
731
--
732
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
733
--
734

    
735
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet}" IS '
736
= regexp_split_to_array("*Accepted_name_species", '' ''::text)
737

    
738
derived column
739

    
740
to modify expr:
741
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet}'')::util.col, $$regexp_split_to_array("*Accepted_name_species", '' ''::text)$$)::util.derived_col_def);
742
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
743

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

    
750

    
751
--
752
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
753
--
754

    
755
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
756
= COALESCE("__accepted_{genus,specific_epithet}"[1],
757
CASE
758
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN "*Accepted_name"
759
    ELSE NULL::text
760
END)
761

    
762
derived column
763

    
764
to modify expr:
765
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$COALESCE("__accepted_{genus,specific_epithet}"[1],
766
CASE
767
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN "*Accepted_name"
768
    ELSE NULL::text
769
END)$$)::util.derived_col_def);
770
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
771

    
772
to rename:
773
# rename column
774
# rename CHECK constraint
775
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
776
';
777

    
778

    
779
--
780
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
781
--
782

    
783
COMMENT ON COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org" IS '
784
= "__accepted_{genus,specific_epithet}"[2]
785

    
786
derived column
787

    
788
to modify expr:
789
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet}"[2]$$)::util.derived_col_def);
790
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
791

    
792
to rename:
793
# rename column
794
# rename CHECK constraint
795
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
796
';
797

    
798

    
799
--
800
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
801
--
802

    
803
COMMENT ON COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
804
= CASE
805
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
806
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
807
    ELSE "*Accepted_name_species"
808
END
809

    
810
derived column
811

    
812
to modify expr:
813
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
814
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
815
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
816
    ELSE "*Accepted_name_species"
817
END$$)::util.derived_col_def);
818
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
819

    
820
to rename:
821
# rename column
822
# rename CHECK constraint
823
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
824
';
825

    
826

    
827
--
828
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
829
--
830

    
831
COMMENT ON COLUMN taxon_match.__accepted_infraspecific_label IS '
832
= ltrim(NULLIF("TNRS".remove_prefix("*Accepted_name_species", "*Accepted_name", require := true, case_sensitive := false), ''''::text), '' ''::text)
833

    
834
derived column
835

    
836
to modify expr:
837
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_label'')::util.col, $$ltrim(NULLIF("TNRS".remove_prefix("*Accepted_name_species", "*Accepted_name", require := true, case_sensitive := false), ''''::text), '' ''::text)$$)::util.derived_col_def);
838
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
839

    
840
to rename:
841
# rename column
842
# rename CHECK constraint
843
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
844
';
845

    
846

    
847
--
848
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
849
--
850

    
851
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
852
= regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
853

    
854
derived column
855

    
856
to modify expr:
857
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);
858
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
859

    
860
to rename:
861
# rename column
862
# rename CHECK constraint
863
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
864
';
865

    
866

    
867
--
868
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
869
--
870

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

    
874
derived column
875

    
876
to modify expr:
877
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);
878
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
879

    
880
to rename:
881
# rename column
882
# rename CHECK constraint
883
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
884
';
885

    
886

    
887
--
888
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
889
--
890

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

    
894
derived column
895

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

    
900
to rename:
901
# rename column
902
# rename CHECK constraint
903
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
904
';
905

    
906

    
907
--
908
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
909
--
910

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

    
914
derived column
915

    
916
to modify expr:
917
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);
918
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
919

    
920
to rename:
921
# rename column
922
# rename CHECK constraint
923
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
924
';
925

    
926

    
927
--
928
-- Name: COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
929
--
930

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

    
934
derived column
935

    
936
to modify expr:
937
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);
938
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
939

    
940
to rename:
941
# rename column
942
# rename CHECK constraint
943
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
944
';
945

    
946

    
947
--
948
-- Name: COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
949
--
950

    
951
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
952
= CASE
953
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
954
    ELSE "*Name_matched_rank"
955
END
956

    
957
derived column
958

    
959
to modify expr:
960
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
961
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
962
    ELSE "*Name_matched_rank"
963
END$$)::util.derived_col_def);
964
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
965

    
966
to rename:
967
# rename column
968
# rename CHECK constraint
969
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
970
';
971

    
972

    
973
--
974
-- Name: COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
975
--
976

    
977
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
978
= CASE
979
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
980
    ELSE "*Name_matched_accepted_family"
981
END
982

    
983
derived column
984

    
985
to modify expr:
986
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
987
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
988
    ELSE "*Name_matched_accepted_family"
989
END$$)::util.derived_col_def);
990
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
991

    
992
to rename:
993
# rename column
994
# rename CHECK constraint
995
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
996
';
997

    
998

    
999
--
1000
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1001
--
1002

    
1003
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
1004
= CASE
1005
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1006
    ELSE "*Genus_matched"
1007
END
1008

    
1009
derived column
1010

    
1011
to modify expr:
1012
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
1013
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1014
    ELSE "*Genus_matched"
1015
END$$)::util.derived_col_def);
1016
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1017

    
1018
to rename:
1019
# rename column
1020
# rename CHECK constraint
1021
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1022
';
1023

    
1024

    
1025
--
1026
-- Name: COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1027
--
1028

    
1029
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
1030
= CASE
1031
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1032
    ELSE "*Specific_epithet_matched"
1033
END
1034

    
1035
derived column
1036

    
1037
to modify expr:
1038
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1039
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1040
    ELSE "*Specific_epithet_matched"
1041
END$$)::util.derived_col_def);
1042
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1043

    
1044
to rename:
1045
# rename column
1046
# rename CHECK constraint
1047
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1048
';
1049

    
1050

    
1051
--
1052
-- Name: COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1053
--
1054

    
1055
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1056
= CASE
1057
    WHEN matched_has_accepted THEN "*Accepted_name_species"
1058
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1059
END
1060

    
1061
derived column
1062

    
1063
to modify expr:
1064
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1065
    WHEN matched_has_accepted THEN "*Accepted_name_species"
1066
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1067
END$$)::util.derived_col_def);
1068
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1069

    
1070
to rename:
1071
# rename column
1072
# rename CHECK constraint
1073
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1074
';
1075

    
1076

    
1077
--
1078
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1079
--
1080

    
1081
COMMENT ON COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
1082
= CASE
1083
    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")
1084
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1085
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1086
END
1087

    
1088
derived column
1089

    
1090
to modify expr:
1091
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
1092
    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")
1093
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1094
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1095
END$$)::util.derived_col_def);
1096
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1097

    
1098
to rename:
1099
# rename column
1100
# rename CHECK constraint
1101
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1102
';
1103

    
1104

    
1105
--
1106
-- Name: COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1107
--
1108

    
1109
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1110
= CASE
1111
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1112
    ELSE "*Infraspecific_rank"
1113
END
1114

    
1115
derived column
1116

    
1117
to modify expr:
1118
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$CASE
1119
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1120
    ELSE "*Infraspecific_rank"
1121
END$$)::util.derived_col_def);
1122
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1123

    
1124
to rename:
1125
# rename column
1126
# rename CHECK constraint
1127
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1128
';
1129

    
1130

    
1131
--
1132
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1133
--
1134

    
1135
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1136
= CASE
1137
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1138
    ELSE "*Infraspecific_epithet_matched"
1139
END
1140

    
1141
derived column
1142

    
1143
to modify expr:
1144
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1145
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1146
    ELSE "*Infraspecific_epithet_matched"
1147
END$$)::util.derived_col_def);
1148
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1149

    
1150
to rename:
1151
# rename column
1152
# rename CHECK constraint
1153
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1154
';
1155

    
1156

    
1157
--
1158
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1159
--
1160

    
1161
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1162
= CASE
1163
    WHEN matched_has_accepted THEN "*Accepted_name"
1164
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1165
END
1166

    
1167
derived column
1168

    
1169
to modify expr:
1170
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1171
    WHEN matched_has_accepted THEN "*Accepted_name"
1172
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1173
END$$)::util.derived_col_def);
1174
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1175

    
1176
to rename:
1177
# rename column
1178
# rename CHECK constraint
1179
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1180
';
1181

    
1182

    
1183
--
1184
-- Name: COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1185
--
1186

    
1187
COMMENT ON COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1188
= CASE
1189
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1190
    ELSE "*Name_matched_author"
1191
END
1192

    
1193
derived column
1194

    
1195
to modify expr:
1196
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1197
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1198
    ELSE "*Name_matched_author"
1199
END$$)::util.derived_col_def);
1200
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1201

    
1202
to rename:
1203
# rename column
1204
# rename CHECK constraint
1205
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1206
';
1207

    
1208

    
1209
--
1210
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1211
--
1212

    
1213
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1214
= CASE
1215
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1216
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1217
END
1218

    
1219
derived column
1220

    
1221
to modify expr:
1222
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$CASE
1223
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1224
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1225
END$$)::util.derived_col_def);
1226
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1227

    
1228
to rename:
1229
# rename column
1230
# rename CHECK constraint
1231
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1232
';
1233

    
1234

    
1235
--
1236
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1237
--
1238

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

    
1310

    
1311
--
1312
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1313
--
1314

    
1315
COMMENT ON VIEW taxon_best_match IS '
1316
to modify:
1317
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1318
SELECT __
1319
$$);
1320
';
1321

    
1322

    
1323
--
1324
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1325
--
1326

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

    
1403

    
1404
--
1405
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1406
--
1407

    
1408
COMMENT ON VIEW "MatchedTaxon" IS '
1409
to modify:
1410
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
1411
SELECT __
1412
$$);
1413
';
1414

    
1415

    
1416
--
1417
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1418
--
1419

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

    
1493

    
1494
--
1495
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1496
--
1497

    
1498
COMMENT ON VIEW "ValidMatchedTaxon" IS '
1499
to update, use * as the column list
1500
';
1501

    
1502

    
1503
--
1504
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1505
--
1506

    
1507
CREATE TABLE batch (
1508
    id text NOT NULL,
1509
    id_by_time text,
1510
    time_submitted timestamp with time zone DEFAULT now(),
1511
    client_version text
1512
);
1513

    
1514

    
1515
--
1516
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1517
--
1518

    
1519
CREATE TABLE batch_download_settings (
1520
    id text NOT NULL,
1521
    "E-mail" text,
1522
    "Id" text,
1523
    "Job type" text,
1524
    "Contains Id" boolean,
1525
    "Start time" text,
1526
    "Finish time" text,
1527
    "TNRS version" text,
1528
    "Sources selected" text,
1529
    "Match threshold" double precision,
1530
    "Classification" text,
1531
    "Allow partial matches?" boolean,
1532
    "Sort by source" boolean,
1533
    "Constrain by higher taxonomy" boolean
1534
);
1535

    
1536

    
1537
--
1538
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
1539
--
1540

    
1541
COMMENT ON TABLE batch_download_settings IS '
1542
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
1543
';
1544

    
1545

    
1546
--
1547
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1548
--
1549

    
1550
CREATE TABLE client_version (
1551
    id text NOT NULL,
1552
    global_rev integer NOT NULL,
1553
    "/lib/tnrs.py rev" integer,
1554
    "/bin/tnrs_db rev" integer
1555
);
1556

    
1557

    
1558
--
1559
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
1560
--
1561

    
1562
COMMENT ON TABLE client_version IS '
1563
contains svn revisions
1564
';
1565

    
1566

    
1567
--
1568
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
1569
--
1570

    
1571
COMMENT ON COLUMN client_version.global_rev IS '
1572
from `svn info .` > Last Changed Rev
1573
';
1574

    
1575

    
1576
--
1577
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
1578
--
1579

    
1580
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
1581
from `svn info lib/tnrs.py` > Last Changed Rev
1582
';
1583

    
1584

    
1585
--
1586
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
1587
--
1588

    
1589
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
1590
from `svn info bin/tnrs_db` > Last Changed Rev
1591
';
1592

    
1593

    
1594
--
1595
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1596
--
1597

    
1598
CREATE VIEW taxon_match_input AS
1599
 SELECT taxon_match."*Name_number" AS "Name_number",
1600
    taxon_match."*Name_submitted" AS "Name_submitted",
1601
    taxon_match."*Overall_score" AS "Overall_score",
1602
    taxon_match."*Name_matched" AS "Name_matched",
1603
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1604
    taxon_match."*Name_score" AS "Name_score",
1605
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1606
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1607
    taxon_match."*Author_matched" AS "Author_matched",
1608
    taxon_match."*Author_score" AS "Author_score",
1609
    taxon_match."*Family_matched" AS "Family_matched",
1610
    taxon_match."*Family_score" AS "Family_score",
1611
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1612
    taxon_match."*Genus_matched" AS "Genus_matched",
1613
    taxon_match."*Genus_score" AS "Genus_score",
1614
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1615
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1616
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1617
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1618
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1619
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1620
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1621
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1622
    taxon_match."*Annotations" AS "Annotations",
1623
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1624
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1625
    taxon_match."*Accepted_name" AS "Accepted_name",
1626
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1627
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1628
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1629
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1630
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1631
    taxon_match."*Selected" AS "Selected",
1632
    taxon_match."*Source" AS "Source",
1633
    taxon_match."*Warnings" AS "Warnings",
1634
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1635
   FROM taxon_match;
1636

    
1637

    
1638
--
1639
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1640
--
1641

    
1642
CREATE TABLE taxon_match_input__copy_to (
1643
    "Name_number" integer,
1644
    "Name_submitted" text,
1645
    "Overall_score" double precision,
1646
    "Name_matched" text,
1647
    "Name_matched_rank" text,
1648
    "Name_score" double precision,
1649
    "Name_matched_author" text,
1650
    "Name_matched_url" text,
1651
    "Author_matched" text,
1652
    "Author_score" double precision,
1653
    "Family_matched" text,
1654
    "Family_score" double precision,
1655
    "Name_matched_accepted_family" text,
1656
    "Genus_matched" text,
1657
    "Genus_score" double precision,
1658
    "Specific_epithet_matched" text,
1659
    "Specific_epithet_score" double precision,
1660
    "Infraspecific_rank" text,
1661
    "Infraspecific_epithet_matched" text,
1662
    "Infraspecific_epithet_score" double precision,
1663
    "Infraspecific_rank_2" text,
1664
    "Infraspecific_epithet_2_matched" text,
1665
    "Infraspecific_epithet_2_score" double precision,
1666
    "Annotations" text,
1667
    "Unmatched_terms" text,
1668
    "Taxonomic_status" text,
1669
    "Accepted_name" text,
1670
    "Accepted_name_author" text,
1671
    "Accepted_name_rank" text,
1672
    "Accepted_name_url" text,
1673
    "Accepted_name_species" text,
1674
    "Accepted_name_family" text,
1675
    "Selected" text,
1676
    "Source" text,
1677
    "Warnings" text,
1678
    "Accepted_name_lsid" text
1679
);
1680

    
1681

    
1682
--
1683
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
1684
--
1685

    
1686
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
1687
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
1688
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
1689
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
1690
    taxon_match."*Genus_matched" AS scrubbed_genus,
1691
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
1692
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
1693
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
1694
    taxon_match."*Name_matched_author" AS scrubbed_author,
1695
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
1696
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
1697
   FROM taxon_match;
1698

    
1699

    
1700
--
1701
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1702
--
1703

    
1704
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1705
to modify:
1706
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1707
SELECT __
1708
$$);
1709

    
1710
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.
1711
';
1712

    
1713

    
1714
--
1715
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1716
--
1717

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

    
1805

    
1806
--
1807
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1808
--
1809

    
1810
COMMENT ON VIEW taxon_scrub IS '
1811
to modify:
1812
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1813
SELECT __
1814
$$);
1815
';
1816

    
1817

    
1818
--
1819
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1820
--
1821

    
1822
ALTER TABLE ONLY batch_download_settings
1823
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1824

    
1825

    
1826
--
1827
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1828
--
1829

    
1830
ALTER TABLE ONLY batch
1831
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1832

    
1833

    
1834
--
1835
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1836
--
1837

    
1838
ALTER TABLE ONLY batch
1839
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1840

    
1841

    
1842
--
1843
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1844
--
1845

    
1846
ALTER TABLE ONLY client_version
1847
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1848

    
1849

    
1850
--
1851
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1852
--
1853

    
1854
ALTER TABLE ONLY taxon_match
1855
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1856

    
1857
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1858

    
1859

    
1860
--
1861
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1862
--
1863

    
1864
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1865

    
1866

    
1867
--
1868
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1869
--
1870

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

    
1873

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

    
1878
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1879

    
1880

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

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

    
1887

    
1888
--
1889
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1890
--
1891

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

    
1894

    
1895
--
1896
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1897
--
1898

    
1899
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1900

    
1901

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

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

    
1908

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

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

    
1915

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

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

    
1922

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

    
1927
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();
1928

    
1929

    
1930
--
1931
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1932
--
1933

    
1934
ALTER TABLE ONLY batch
1935
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1936

    
1937

    
1938
--
1939
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1940
--
1941

    
1942
ALTER TABLE ONLY batch_download_settings
1943
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1944

    
1945

    
1946
--
1947
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1948
--
1949

    
1950
ALTER TABLE ONLY taxon_match
1951
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1952

    
1953

    
1954
--
1955
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1956
--
1957

    
1958
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1959
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1960
GRANT ALL ON SCHEMA "TNRS" TO bien;
1961
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1962

    
1963

    
1964
--
1965
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1966
--
1967

    
1968
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1969
REVOKE ALL ON TABLE taxon_match FROM bien;
1970
GRANT ALL ON TABLE taxon_match TO bien;
1971
GRANT SELECT ON TABLE taxon_match TO bien_read;
1972

    
1973

    
1974
--
1975
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1976
--
1977

    
1978
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1979
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1980
GRANT ALL ON TABLE taxon_best_match TO bien;
1981
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1982

    
1983

    
1984
--
1985
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1986
--
1987

    
1988
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
1989
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
1990
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
1991
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
1992

    
1993

    
1994
--
1995
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1996
--
1997

    
1998
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
1999
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
2000
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
2001
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
2002

    
2003

    
2004
--
2005
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
2006
--
2007

    
2008
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
2009
REVOKE ALL ON TABLE taxon_match_input FROM bien;
2010
GRANT ALL ON TABLE taxon_match_input TO bien;
2011
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
2012

    
2013

    
2014
--
2015
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
2016
--
2017

    
2018
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
2019
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
2020
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
2021
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
2022

    
2023

    
2024
--
2025
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
2026
--
2027

    
2028
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
2029
REVOKE ALL ON TABLE taxon_scrub FROM bien;
2030
GRANT ALL ON TABLE taxon_scrub TO bien;
2031
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
2032

    
2033

    
2034
--
2035
-- PostgreSQL database dump complete
2036
--
2037

    
(7-7/9)