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: taxon_match__batch_begin(); Type: FUNCTION; Schema: TNRS; Owner: -
97
--
98

    
99
CREATE FUNCTION taxon_match__batch_begin() RETURNS trigger
100
    LANGUAGE plpgsql
101
    AS $$
102
BEGIN
103
	PERFORM util.seq__reset('pg_temp.taxon_match__match_num__seq', 0);
104
	RETURN NULL;
105
END;
106
$$;
107

    
108

    
109
--
110
-- Name: taxon_match__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
111
--
112

    
113
CREATE FUNCTION taxon_match__fill() RETURNS trigger
114
    LANGUAGE plpgsql
115
    AS $$
116
BEGIN
117
	DECLARE
118
		"Specific_epithet_is_plant" boolean :=
119
			(CASE
120
			WHEN   new."*Infraspecific_epithet_matched"	 IS NOT NULL
121
				OR new."*Infraspecific_epithet_2_matched" IS NOT NULL
122
				OR new."*Specific_epithet_score" >= 0.9 -- fuzzy match
123
				THEN true
124
			ELSE NULL -- ambiguous
125
			END);
126
		never_homonym boolean = COALESCE(new."*Author_score" >= 0.6, false);
127
			-- author disambiguates
128
		family_is_homonym boolean = NOT never_homonym
129
			AND "TNRS".family_is_homonym(new."*Family_matched");
130
		genus_is_homonym  boolean = NOT never_homonym
131
			AND "TNRS".genus_is_homonym(new."*Genus_matched");
132
	BEGIN
133
		/* exclude homonyms because these are not valid matches (TNRS provides a
134
		name, but the name is not meaningful because it is not unambiguous) */
135
		new.is_valid_match = new."*Taxonomic_status" != 'Invalid'
136
			AND COALESCE(CASE
137
			WHEN new."*Family_score" = 1 AND NOT family_is_homonym -- exact match
138
				THEN true
139
			ELSE -- consider genus
140
				(CASE
141
				WHEN new."*Genus_score" =  1	   -- exact match
142
					THEN
143
					(CASE
144
					WHEN NOT genus_is_homonym THEN true
145
					ELSE "Specific_epithet_is_plant"
146
					END)
147
				WHEN new."*Genus_score" >= 0.85 -- fuzzy match
148
					THEN "Specific_epithet_is_plant"
149
				ELSE NULL -- ambiguous
150
				END)
151
			END, false);
152
	END;
153
	
154
	DECLARE
155
		matched_taxon_name_with_author text = NULLIF(concat_ws(' '
156
			, NULLIF(NULLIF(new."*Name_matched_accepted_family", 'Unknown'),
157
				new."*Name_matched")
158
			, NULLIF(new."*Name_matched", 'No suitable matches found.')
159
			, new."*Name_matched_author"
160
			), '');
161
		accepted_taxon_name_with_author text = NULLIF(concat_ws(' '
162
			, NULLIF(NULLIF(new."*Accepted_name_family", 'Unknown'),
163
				new."*Accepted_name")
164
			, new."*Accepted_name"
165
			, new."*Accepted_name_author"
166
			), '');
167
	BEGIN
168
		new.scrubbed_unique_taxon_name = COALESCE(
169
			accepted_taxon_name_with_author, matched_taxon_name_with_author);
170
	END;
171
	
172
	RETURN new;
173
END;
174
$$;
175

    
176

    
177
--
178
-- Name: FUNCTION taxon_match__fill(); Type: COMMENT; Schema: TNRS; Owner: -
179
--
180

    
181
COMMENT ON FUNCTION taxon_match__fill() IS '
182
IMPORTANT: when changing this function, you must regenerate the derived cols:
183
UPDATE "TNRS".taxon_match SET "Name_submitted" = "Name_submitted"
184
runtime: 30 min ("5564082 rows affected, 1918900 ms execution time")
185
VACUUM ANALYZE "TNRS".taxon_match -- to remove previous rows
186
runtime: 1.5 min ("92633 ms")
187
';
188

    
189

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

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

    
306

    
307
--
308
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
309
--
310

    
311
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
312
autogenerated, do not edit
313

    
314
to regenerate:
315
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
316
';
317

    
318

    
319
--
320
-- Name: taxon_match__match_num__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
321
--
322

    
323
CREATE FUNCTION taxon_match__match_num__fill() RETURNS trigger
324
    LANGUAGE plpgsql
325
    AS $$
326
BEGIN
327
	IF new.match_num IS NULL THEN
328
		new.match_num = "TNRS".taxon_match__match_num__next();
329
	END IF;
330
	RETURN new;
331
END;
332
$$;
333

    
334

    
335
--
336
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
337
--
338

    
339
CREATE FUNCTION taxon_match__match_num__next() RETURNS bigint
340
    LANGUAGE sql
341
    AS $$
342
SELECT nextval('pg_temp.taxon_match__match_num__seq');
343
$$;
344

    
345

    
346
--
347
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
348
--
349

    
350
CREATE FUNCTION taxon_match_input__copy_to__insert() RETURNS trigger
351
    LANGUAGE plpgsql
352
    AS $$
353
BEGIN
354
	INSERT INTO "TNRS".taxon_match_input SELECT new.*;
355
	RETURN NULL;
356
END;
357
$$;
358

    
359

    
360
--
361
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
362
--
363

    
364
CREATE FUNCTION taxon_name_is_safe(taxon_name text) RETURNS boolean
365
    LANGUAGE sql IMMUTABLE
366
    AS $_$
367
SELECT NOT ($1 = ANY("TNRS".unsafe_taxon_names()))
368
$_$;
369

    
370

    
371
--
372
-- Name: unsafe_taxon_names(); Type: FUNCTION; Schema: TNRS; Owner: -
373
--
374

    
375
CREATE FUNCTION unsafe_taxon_names() RETURNS text[]
376
    LANGUAGE sql IMMUTABLE
377
    AS $$
378
SELECT ARRAY[
379
]::text[]
380
$$;
381

    
382

    
383
SET default_tablespace = '';
384

    
385
SET default_with_oids = false;
386

    
387
--
388
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
389
--
390

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

    
546

    
547
--
548
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
549
--
550

    
551
COMMENT ON TABLE taxon_match IS '
552
whenever columns are renamed:
553
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
554

    
555
to remove columns or add columns at the end:
556
$ rm=1 inputs/.TNRS/data.sql.run
557
$ make schemas/remake
558

    
559
to add columns in the middle:
560
make the changes in inputs/.TNRS/schema.sql
561
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS
562
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
563
SELECT util.derived_cols_repopulate(''"TNRS".taxon_match'');
564
$ make schemas/remake
565

    
566
to populate a new column:
567
ALTER TABLE "TNRS".taxon_match DISABLE TRIGGER taxon_match__fill; --speeds up update
568
UPDATE "TNRS".taxon_match SET "col" = value;
569
	-- runtime: 30 min ("5564201 rows affected, 1624829 ms execution time")
570
CLUSTER "TNRS".taxon_match; -- ensure rows are exported in sorted order
571
ALTER TABLE "TNRS".taxon_match ENABLE TRIGGER taxon_match__fill;
572
VACUUM ANALYZE "TNRS".taxon_match --remove previous rows; runtime: 1.5 min ("92633 ms")
573

    
574
to add a constraint: runtime: 3 min ("173620 ms")
575
';
576

    
577

    
578
--
579
-- Name: COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
580
--
581

    
582
COMMENT ON COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS '
583
= "*Unmatched_terms"
584

    
585
derived column
586

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

    
591
to rename:
592
# rename column
593
# rename CHECK constraint
594
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
595
';
596

    
597

    
598
--
599
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
600
--
601

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

    
605
derived column
606

    
607
to modify expr:
608
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);
609
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
610

    
611
to rename:
612
# rename column
613
# rename CHECK constraint
614
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
615
';
616

    
617

    
618
--
619
-- Name: COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
620
--
621

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

    
625
derived column
626

    
627
to modify expr:
628
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);
629
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
630

    
631
to rename:
632
# rename column
633
# rename CHECK constraint
634
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
635
';
636

    
637

    
638
--
639
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
640
--
641

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

    
645
derived column
646

    
647
to modify expr:
648
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);
649
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
650

    
651
to rename:
652
# rename column
653
# rename CHECK constraint
654
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
655
';
656

    
657

    
658
--
659
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
660
--
661

    
662
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
663
= "*Accepted_name" IS NOT NULL
664

    
665
derived column
666

    
667
to modify expr:
668
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
669
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
670

    
671
to rename:
672
# rename column
673
# rename CHECK constraint
674
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
675
';
676

    
677

    
678
--
679
-- Name: COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
680
--
681

    
682
COMMENT ON COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org" IS '
683
= COALESCE("*Accepted_name_family",
684
CASE
685
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
686
    ELSE NULL::text
687
END)
688

    
689
derived column
690

    
691
to modify expr:
692
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col, $$COALESCE("*Accepted_name_family",
693
CASE
694
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
695
    ELSE NULL::text
696
END)$$)::util.derived_col_def);
697
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
698

    
699
to rename:
700
# rename column
701
# rename CHECK constraint
702
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
703
';
704

    
705

    
706
--
707
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
708
--
709

    
710
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet}" IS '
711
= regexp_split_to_array("*Accepted_name_species", '' ''::text)
712

    
713
derived column
714

    
715
to modify expr:
716
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);
717
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
718

    
719
to rename:
720
# rename column
721
# rename CHECK constraint
722
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
723
';
724

    
725

    
726
--
727
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
728
--
729

    
730
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
731
= COALESCE("__accepted_{genus,specific_epithet}"[1],
732
CASE
733
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN "*Accepted_name"
734
    ELSE NULL::text
735
END)
736

    
737
derived column
738

    
739
to modify expr:
740
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$COALESCE("__accepted_{genus,specific_epithet}"[1],
741
CASE
742
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN "*Accepted_name"
743
    ELSE NULL::text
744
END)$$)::util.derived_col_def);
745
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
746

    
747
to rename:
748
# rename column
749
# rename CHECK constraint
750
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
751
';
752

    
753

    
754
--
755
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
756
--
757

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

    
761
derived column
762

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

    
767
to rename:
768
# rename column
769
# rename CHECK constraint
770
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
771
';
772

    
773

    
774
--
775
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
776
--
777

    
778
COMMENT ON COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
779
= CASE
780
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
781
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
782
    ELSE "*Accepted_name_species"
783
END
784

    
785
derived column
786

    
787
to modify expr:
788
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
789
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
790
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
791
    ELSE "*Accepted_name_species"
792
END$$)::util.derived_col_def);
793
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
794

    
795
to rename:
796
# rename column
797
# rename CHECK constraint
798
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
799
';
800

    
801

    
802
--
803
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
804
--
805

    
806
COMMENT ON COLUMN taxon_match.__accepted_infraspecific_label IS '
807
= ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''''::text), '' ''::text)
808

    
809
derived column
810

    
811
to modify expr:
812
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_label'')::util.col, $$ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''''::text), '' ''::text)$$)::util.derived_col_def);
813
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
814

    
815
to rename:
816
# rename column
817
# rename CHECK constraint
818
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
819
';
820

    
821

    
822
--
823
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
824
--
825

    
826
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
827
= regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
828

    
829
derived column
830

    
831
to modify expr:
832
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);
833
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
834

    
835
to rename:
836
# rename column
837
# rename CHECK constraint
838
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
839
';
840

    
841

    
842
--
843
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
844
--
845

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

    
849
derived column
850

    
851
to modify expr:
852
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);
853
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
854

    
855
to rename:
856
# rename column
857
# rename CHECK constraint
858
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
859
';
860

    
861

    
862
--
863
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
864
--
865

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

    
869
derived column
870

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

    
875
to rename:
876
# rename column
877
# rename CHECK constraint
878
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
879
';
880

    
881

    
882
--
883
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
884
--
885

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

    
889
derived column
890

    
891
to modify expr:
892
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);
893
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
894

    
895
to rename:
896
# rename column
897
# rename CHECK constraint
898
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
899
';
900

    
901

    
902
--
903
-- Name: COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
904
--
905

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

    
909
derived column
910

    
911
to modify expr:
912
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);
913
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
914

    
915
to rename:
916
# rename column
917
# rename CHECK constraint
918
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
919
';
920

    
921

    
922
--
923
-- Name: COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
924
--
925

    
926
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
927
= CASE
928
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
929
    ELSE "*Name_matched_rank"
930
END
931

    
932
derived column
933

    
934
to modify expr:
935
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
936
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
937
    ELSE "*Name_matched_rank"
938
END$$)::util.derived_col_def);
939
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
940

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

    
947

    
948
--
949
-- Name: COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
950
--
951

    
952
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
953
= CASE
954
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
955
    ELSE "*Name_matched_accepted_family"
956
END
957

    
958
derived column
959

    
960
to modify expr:
961
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
962
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
963
    ELSE "*Name_matched_accepted_family"
964
END$$)::util.derived_col_def);
965
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
966

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

    
973

    
974
--
975
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
976
--
977

    
978
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
979
= CASE
980
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
981
    ELSE "*Genus_matched"
982
END
983

    
984
derived column
985

    
986
to modify expr:
987
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
988
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
989
    ELSE "*Genus_matched"
990
END$$)::util.derived_col_def);
991
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
992

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

    
999

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

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

    
1010
derived column
1011

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

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

    
1025

    
1026
--
1027
-- Name: COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1028
--
1029

    
1030
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1031
= CASE
1032
    WHEN matched_has_accepted THEN "*Accepted_name_species"
1033
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1034
END
1035

    
1036
derived column
1037

    
1038
to modify expr:
1039
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1040
    WHEN matched_has_accepted THEN "*Accepted_name_species"
1041
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1042
END$$)::util.derived_col_def);
1043
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1044

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

    
1051

    
1052
--
1053
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1054
--
1055

    
1056
COMMENT ON COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
1057
= CASE
1058
    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")
1059
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1060
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1061
END
1062

    
1063
derived column
1064

    
1065
to modify expr:
1066
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
1067
    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")
1068
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1069
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1070
END$$)::util.derived_col_def);
1071
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1072

    
1073
to rename:
1074
# rename column
1075
# rename CHECK constraint
1076
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1077
';
1078

    
1079

    
1080
--
1081
-- Name: COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1082
--
1083

    
1084
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1085
= CASE
1086
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1087
    ELSE "*Infraspecific_rank"
1088
END
1089

    
1090
derived column
1091

    
1092
to modify expr:
1093
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$CASE
1094
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1095
    ELSE "*Infraspecific_rank"
1096
END$$)::util.derived_col_def);
1097
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1098

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

    
1105

    
1106
--
1107
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1108
--
1109

    
1110
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1111
= CASE
1112
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1113
    ELSE "*Infraspecific_epithet_matched"
1114
END
1115

    
1116
derived column
1117

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

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

    
1131

    
1132
--
1133
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1134
--
1135

    
1136
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1137
= CASE
1138
    WHEN matched_has_accepted THEN "*Accepted_name"
1139
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1140
END
1141

    
1142
derived column
1143

    
1144
to modify expr:
1145
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1146
    WHEN matched_has_accepted THEN "*Accepted_name"
1147
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1148
END$$)::util.derived_col_def);
1149
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1150

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

    
1157

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

    
1162
COMMENT ON COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1163
= CASE
1164
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1165
    ELSE "*Name_matched_author"
1166
END
1167

    
1168
derived column
1169

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

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

    
1183

    
1184
--
1185
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1186
--
1187

    
1188
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1189
= CASE
1190
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1191
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1192
END
1193

    
1194
derived column
1195

    
1196
to modify expr:
1197
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$CASE
1198
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1199
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1200
END$$)::util.derived_col_def);
1201
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1202

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

    
1209

    
1210
--
1211
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1212
--
1213

    
1214
CREATE VIEW taxon_best_match AS
1215
 SELECT taxon_match.batch,
1216
    taxon_match.match_num,
1217
    taxon_match."*Name_number",
1218
    taxon_match."*Name_submitted",
1219
    taxon_match."*Overall_score",
1220
    taxon_match."*Name_matched",
1221
    taxon_match."*Name_matched_rank",
1222
    taxon_match."*Name_score",
1223
    taxon_match."*Name_matched_author",
1224
    taxon_match."*Name_matched_url",
1225
    taxon_match."*Author_matched",
1226
    taxon_match."*Author_score",
1227
    taxon_match."*Family_matched",
1228
    taxon_match."*Family_score",
1229
    taxon_match."*Name_matched_accepted_family",
1230
    taxon_match."*Genus_matched",
1231
    taxon_match."*Genus_score",
1232
    taxon_match."*Specific_epithet_matched",
1233
    taxon_match."*Specific_epithet_score",
1234
    taxon_match."*Infraspecific_rank",
1235
    taxon_match."*Infraspecific_epithet_matched",
1236
    taxon_match."*Infraspecific_epithet_score",
1237
    taxon_match."*Infraspecific_rank_2",
1238
    taxon_match."*Infraspecific_epithet_2_matched",
1239
    taxon_match."*Infraspecific_epithet_2_score",
1240
    taxon_match."*Annotations",
1241
    taxon_match."*Unmatched_terms",
1242
    taxon_match."*Taxonomic_status",
1243
    taxon_match."*Accepted_name",
1244
    taxon_match."*Accepted_name_author",
1245
    taxon_match."*Accepted_name_rank",
1246
    taxon_match."*Accepted_name_url",
1247
    taxon_match."*Accepted_name_species",
1248
    taxon_match."*Accepted_name_family",
1249
    taxon_match."*Selected",
1250
    taxon_match."*Source",
1251
    taxon_match."*Warnings",
1252
    taxon_match."*Accepted_name_lsid",
1253
    taxon_match.is_valid_match,
1254
    taxon_match.scrubbed_unique_taxon_name,
1255
    taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1256
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1257
    taxon_match.matched_has_accepted,
1258
    taxon_match."__accepted_{genus,specific_epithet}",
1259
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
1260
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1261
    taxon_match.__accepted_infraspecific_label,
1262
    taxon_match."__accepted_infraspecific_{rank,epithet}",
1263
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1264
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1265
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1266
    taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1267
    taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1268
    taxon_match."[scrubbed_]genus__@DwC__@vegpath.org",
1269
    taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1270
    taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1271
    taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1272
    taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1273
    taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1274
    taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1275
    taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1276
   FROM taxon_match
1277
  WHERE (taxon_match."*Selected" = 'true'::text);
1278

    
1279

    
1280
--
1281
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1282
--
1283

    
1284
COMMENT ON VIEW taxon_best_match IS '
1285
to modify:
1286
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1287
SELECT __
1288
$$);
1289
';
1290

    
1291

    
1292
--
1293
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1294
--
1295

    
1296
CREATE VIEW "MatchedTaxon" AS
1297
 SELECT taxon_best_match.batch,
1298
    taxon_best_match.match_num,
1299
    taxon_best_match."*Name_number",
1300
    taxon_best_match."*Name_submitted",
1301
    taxon_best_match."*Overall_score",
1302
    taxon_best_match."*Name_matched",
1303
    taxon_best_match."*Name_matched_rank",
1304
    taxon_best_match."*Name_score",
1305
    taxon_best_match."*Name_matched_author",
1306
    taxon_best_match."*Name_matched_url",
1307
    taxon_best_match."*Author_matched",
1308
    taxon_best_match."*Author_score",
1309
    taxon_best_match."*Family_matched",
1310
    taxon_best_match."*Family_score",
1311
    taxon_best_match."*Name_matched_accepted_family",
1312
    taxon_best_match."*Genus_matched",
1313
    taxon_best_match."*Genus_score",
1314
    taxon_best_match."*Specific_epithet_matched",
1315
    taxon_best_match."*Specific_epithet_score",
1316
    taxon_best_match."*Infraspecific_rank",
1317
    taxon_best_match."*Infraspecific_epithet_matched",
1318
    taxon_best_match."*Infraspecific_epithet_score",
1319
    taxon_best_match."*Infraspecific_rank_2",
1320
    taxon_best_match."*Infraspecific_epithet_2_matched",
1321
    taxon_best_match."*Infraspecific_epithet_2_score",
1322
    taxon_best_match."*Annotations",
1323
    taxon_best_match."*Unmatched_terms",
1324
    taxon_best_match."*Taxonomic_status",
1325
    taxon_best_match."*Accepted_name",
1326
    taxon_best_match."*Accepted_name_author",
1327
    taxon_best_match."*Accepted_name_rank",
1328
    taxon_best_match."*Accepted_name_url",
1329
    taxon_best_match."*Accepted_name_species",
1330
    taxon_best_match."*Accepted_name_family",
1331
    taxon_best_match."*Selected",
1332
    taxon_best_match."*Source",
1333
    taxon_best_match."*Warnings",
1334
    taxon_best_match."*Accepted_name_lsid",
1335
    taxon_best_match.is_valid_match,
1336
    taxon_best_match.scrubbed_unique_taxon_name,
1337
    taxon_best_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1338
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1339
    taxon_best_match.matched_has_accepted,
1340
    taxon_best_match."__accepted_{genus,specific_epithet}",
1341
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
1342
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1343
    taxon_best_match.__accepted_infraspecific_label,
1344
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
1345
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1346
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1347
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1348
    taxon_best_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1349
    taxon_best_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1350
    taxon_best_match."[scrubbed_]genus__@DwC__@vegpath.org",
1351
    taxon_best_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1352
    taxon_best_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1353
    taxon_best_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1354
    taxon_best_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1355
    taxon_best_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1356
    taxon_best_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1357
    taxon_best_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1358
    map_taxonomic_status(taxon_best_match."*Taxonomic_status", taxon_best_match."*Accepted_name") AS "taxonomicStatus",
1359
        CASE
1360
            WHEN (taxon_best_match."*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name_family", taxon_best_match."*Unmatched_terms")
1361
            WHEN (taxon_best_match."*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name", taxon_best_match."*Unmatched_terms")
1362
            ELSE taxon_best_match."*Accepted_name_species"
1363
        END AS accepted_morphospecies_binomial
1364
   FROM taxon_best_match;
1365

    
1366

    
1367
--
1368
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1369
--
1370

    
1371
COMMENT ON VIEW "MatchedTaxon" IS '
1372
to modify:
1373
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
1374
SELECT __
1375
$$);
1376
';
1377

    
1378

    
1379
--
1380
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1381
--
1382

    
1383
CREATE VIEW "ValidMatchedTaxon" AS
1384
 SELECT "MatchedTaxon".batch,
1385
    "MatchedTaxon".match_num,
1386
    "MatchedTaxon"."*Name_number",
1387
    "MatchedTaxon"."*Name_submitted",
1388
    "MatchedTaxon"."*Overall_score",
1389
    "MatchedTaxon"."*Name_matched",
1390
    "MatchedTaxon"."*Name_matched_rank",
1391
    "MatchedTaxon"."*Name_score",
1392
    "MatchedTaxon"."*Name_matched_author",
1393
    "MatchedTaxon"."*Name_matched_url",
1394
    "MatchedTaxon"."*Author_matched",
1395
    "MatchedTaxon"."*Author_score",
1396
    "MatchedTaxon"."*Family_matched",
1397
    "MatchedTaxon"."*Family_score",
1398
    "MatchedTaxon"."*Name_matched_accepted_family",
1399
    "MatchedTaxon"."*Genus_matched",
1400
    "MatchedTaxon"."*Genus_score",
1401
    "MatchedTaxon"."*Specific_epithet_matched",
1402
    "MatchedTaxon"."*Specific_epithet_score",
1403
    "MatchedTaxon"."*Infraspecific_rank",
1404
    "MatchedTaxon"."*Infraspecific_epithet_matched",
1405
    "MatchedTaxon"."*Infraspecific_epithet_score",
1406
    "MatchedTaxon"."*Infraspecific_rank_2",
1407
    "MatchedTaxon"."*Infraspecific_epithet_2_matched",
1408
    "MatchedTaxon"."*Infraspecific_epithet_2_score",
1409
    "MatchedTaxon"."*Annotations",
1410
    "MatchedTaxon"."*Unmatched_terms",
1411
    "MatchedTaxon"."*Taxonomic_status",
1412
    "MatchedTaxon"."*Accepted_name",
1413
    "MatchedTaxon"."*Accepted_name_author",
1414
    "MatchedTaxon"."*Accepted_name_rank",
1415
    "MatchedTaxon"."*Accepted_name_url",
1416
    "MatchedTaxon"."*Accepted_name_species",
1417
    "MatchedTaxon"."*Accepted_name_family",
1418
    "MatchedTaxon"."*Selected",
1419
    "MatchedTaxon"."*Source",
1420
    "MatchedTaxon"."*Warnings",
1421
    "MatchedTaxon"."*Accepted_name_lsid",
1422
    "MatchedTaxon".is_valid_match,
1423
    "MatchedTaxon".scrubbed_unique_taxon_name,
1424
    "MatchedTaxon"."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1425
    "MatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1426
    "MatchedTaxon".matched_has_accepted,
1427
    "MatchedTaxon"."__accepted_{genus,specific_epithet}",
1428
    "MatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1429
    "MatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1430
    "MatchedTaxon".__accepted_infraspecific_label,
1431
    "MatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1432
    "MatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1433
    "MatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1434
    "MatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1435
    "MatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1436
    "MatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1437
    "MatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org",
1438
    "MatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1439
    "MatchedTaxon"."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1440
    "MatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1441
    "MatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1442
    "MatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1443
    "MatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1444
    "MatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1445
    "MatchedTaxon"."taxonomicStatus",
1446
    "MatchedTaxon".accepted_morphospecies_binomial
1447
   FROM "MatchedTaxon"
1448
  WHERE "MatchedTaxon".is_valid_match;
1449

    
1450

    
1451
--
1452
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1453
--
1454

    
1455
COMMENT ON VIEW "ValidMatchedTaxon" IS '
1456
to update, use * as the column list
1457
';
1458

    
1459

    
1460
--
1461
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1462
--
1463

    
1464
CREATE TABLE batch (
1465
    id text NOT NULL,
1466
    id_by_time text,
1467
    time_submitted timestamp with time zone DEFAULT now(),
1468
    client_version text
1469
);
1470

    
1471

    
1472
--
1473
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1474
--
1475

    
1476
CREATE TABLE batch_download_settings (
1477
    id text NOT NULL,
1478
    "E-mail" text,
1479
    "Id" text,
1480
    "Job type" text,
1481
    "Contains Id" boolean,
1482
    "Start time" text,
1483
    "Finish time" text,
1484
    "TNRS version" text,
1485
    "Sources selected" text,
1486
    "Match threshold" double precision,
1487
    "Classification" text,
1488
    "Allow partial matches?" boolean,
1489
    "Sort by source" boolean,
1490
    "Constrain by higher taxonomy" boolean
1491
);
1492

    
1493

    
1494
--
1495
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
1496
--
1497

    
1498
COMMENT ON TABLE batch_download_settings IS '
1499
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
1500
';
1501

    
1502

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

    
1507
CREATE TABLE client_version (
1508
    id text NOT NULL,
1509
    global_rev integer NOT NULL,
1510
    "/lib/tnrs.py rev" integer,
1511
    "/bin/tnrs_db rev" integer
1512
);
1513

    
1514

    
1515
--
1516
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
1517
--
1518

    
1519
COMMENT ON TABLE client_version IS '
1520
contains svn revisions
1521
';
1522

    
1523

    
1524
--
1525
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
1526
--
1527

    
1528
COMMENT ON COLUMN client_version.global_rev IS '
1529
from `svn info .` > Last Changed Rev
1530
';
1531

    
1532

    
1533
--
1534
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
1535
--
1536

    
1537
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
1538
from `svn info lib/tnrs.py` > Last Changed Rev
1539
';
1540

    
1541

    
1542
--
1543
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
1544
--
1545

    
1546
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
1547
from `svn info bin/tnrs_db` > Last Changed Rev
1548
';
1549

    
1550

    
1551
--
1552
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1553
--
1554

    
1555
CREATE VIEW taxon_match_input AS
1556
 SELECT taxon_match."*Name_number" AS "Name_number",
1557
    taxon_match."*Name_submitted" AS "Name_submitted",
1558
    taxon_match."*Overall_score" AS "Overall_score",
1559
    taxon_match."*Name_matched" AS "Name_matched",
1560
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1561
    taxon_match."*Name_score" AS "Name_score",
1562
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1563
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1564
    taxon_match."*Author_matched" AS "Author_matched",
1565
    taxon_match."*Author_score" AS "Author_score",
1566
    taxon_match."*Family_matched" AS "Family_matched",
1567
    taxon_match."*Family_score" AS "Family_score",
1568
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1569
    taxon_match."*Genus_matched" AS "Genus_matched",
1570
    taxon_match."*Genus_score" AS "Genus_score",
1571
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1572
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1573
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1574
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1575
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1576
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1577
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1578
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1579
    taxon_match."*Annotations" AS "Annotations",
1580
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1581
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1582
    taxon_match."*Accepted_name" AS "Accepted_name",
1583
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1584
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1585
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1586
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1587
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1588
    taxon_match."*Selected" AS "Selected",
1589
    taxon_match."*Source" AS "Source",
1590
    taxon_match."*Warnings" AS "Warnings",
1591
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1592
   FROM taxon_match;
1593

    
1594

    
1595
--
1596
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1597
--
1598

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

    
1638

    
1639
--
1640
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
1641
--
1642

    
1643
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
1644
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
1645
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
1646
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
1647
    taxon_match."*Genus_matched" AS scrubbed_genus,
1648
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
1649
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
1650
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
1651
    taxon_match."*Name_matched_author" AS scrubbed_author,
1652
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
1653
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
1654
   FROM taxon_match;
1655

    
1656

    
1657
--
1658
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1659
--
1660

    
1661
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1662
to modify:
1663
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1664
SELECT __
1665
$$);
1666

    
1667
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.
1668
';
1669

    
1670

    
1671
--
1672
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1673
--
1674

    
1675
CREATE VIEW taxon_scrub AS
1676
 SELECT "ValidMatchedTaxon".scrubbed_unique_taxon_name,
1677
    "ValidMatchedTaxon".batch,
1678
    "ValidMatchedTaxon".match_num,
1679
    "ValidMatchedTaxon"."*Name_number",
1680
    "ValidMatchedTaxon"."*Name_submitted",
1681
    "ValidMatchedTaxon"."*Overall_score",
1682
    "ValidMatchedTaxon"."*Name_matched",
1683
    "ValidMatchedTaxon"."*Name_matched_rank",
1684
    "ValidMatchedTaxon"."*Name_score",
1685
    "ValidMatchedTaxon"."*Name_matched_author",
1686
    "ValidMatchedTaxon"."*Name_matched_url",
1687
    "ValidMatchedTaxon"."*Author_matched",
1688
    "ValidMatchedTaxon"."*Author_score",
1689
    "ValidMatchedTaxon"."*Family_matched",
1690
    "ValidMatchedTaxon"."*Family_score",
1691
    "ValidMatchedTaxon"."*Name_matched_accepted_family",
1692
    "ValidMatchedTaxon"."*Genus_matched",
1693
    "ValidMatchedTaxon"."*Genus_score",
1694
    "ValidMatchedTaxon"."*Specific_epithet_matched",
1695
    "ValidMatchedTaxon"."*Specific_epithet_score",
1696
    "ValidMatchedTaxon"."*Infraspecific_rank",
1697
    "ValidMatchedTaxon"."*Infraspecific_epithet_matched",
1698
    "ValidMatchedTaxon"."*Infraspecific_epithet_score",
1699
    "ValidMatchedTaxon"."*Infraspecific_rank_2",
1700
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_matched",
1701
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_score",
1702
    "ValidMatchedTaxon"."*Annotations",
1703
    "ValidMatchedTaxon"."*Unmatched_terms",
1704
    "ValidMatchedTaxon"."*Taxonomic_status",
1705
    "ValidMatchedTaxon"."*Accepted_name",
1706
    "ValidMatchedTaxon"."*Accepted_name_author",
1707
    "ValidMatchedTaxon"."*Accepted_name_rank",
1708
    "ValidMatchedTaxon"."*Accepted_name_url",
1709
    "ValidMatchedTaxon"."*Accepted_name_species",
1710
    "ValidMatchedTaxon"."*Accepted_name_family",
1711
    "ValidMatchedTaxon"."*Selected",
1712
    "ValidMatchedTaxon"."*Source",
1713
    "ValidMatchedTaxon"."*Warnings",
1714
    "ValidMatchedTaxon"."*Accepted_name_lsid",
1715
    "ValidMatchedTaxon".is_valid_match,
1716
    "ValidMatchedTaxon"."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1717
    "ValidMatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1718
    "ValidMatchedTaxon".matched_has_accepted,
1719
    "ValidMatchedTaxon"."__accepted_{genus,specific_epithet}",
1720
    "ValidMatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1721
    "ValidMatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1722
    "ValidMatchedTaxon".__accepted_infraspecific_label,
1723
    "ValidMatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1724
    "ValidMatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1725
    "ValidMatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1726
    "ValidMatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1727
    "ValidMatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1728
    "ValidMatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1729
    "ValidMatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org",
1730
    "ValidMatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1731
    "ValidMatchedTaxon"."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1732
    "ValidMatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1733
    "ValidMatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1734
    "ValidMatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1735
    "ValidMatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1736
    "ValidMatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1737
    "ValidMatchedTaxon"."taxonomicStatus",
1738
    "ValidMatchedTaxon".accepted_morphospecies_binomial,
1739
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank,
1740
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family,
1741
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus,
1742
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet,
1743
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_rank,
1744
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_epithet,
1745
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_author,
1746
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author,
1747
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_with_author,
1748
        CASE
1749
            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")
1750
            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")
1751
            ELSE (("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus || ' '::text) || "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet)
1752
        END AS scrubbed_morphospecies_binomial
1753
   FROM ("ValidMatchedTaxon"
1754
   LEFT JOIN "taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name));
1755

    
1756

    
1757
--
1758
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1759
--
1760

    
1761
COMMENT ON VIEW taxon_scrub IS '
1762
to modify:
1763
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1764
SELECT __
1765
$$);
1766
';
1767

    
1768

    
1769
--
1770
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1771
--
1772

    
1773
ALTER TABLE ONLY batch_download_settings
1774
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1775

    
1776

    
1777
--
1778
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1779
--
1780

    
1781
ALTER TABLE ONLY batch
1782
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1783

    
1784

    
1785
--
1786
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1787
--
1788

    
1789
ALTER TABLE ONLY batch
1790
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1791

    
1792

    
1793
--
1794
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1795
--
1796

    
1797
ALTER TABLE ONLY client_version
1798
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1799

    
1800

    
1801
--
1802
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1803
--
1804

    
1805
ALTER TABLE ONLY taxon_match
1806
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1807

    
1808
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1809

    
1810

    
1811
--
1812
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1813
--
1814

    
1815
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1816

    
1817

    
1818
--
1819
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1820
--
1821

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

    
1824

    
1825
--
1826
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1827
--
1828

    
1829
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1830

    
1831

    
1832
--
1833
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1834
--
1835

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

    
1838

    
1839
--
1840
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1841
--
1842

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

    
1845

    
1846
--
1847
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1848
--
1849

    
1850
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1851

    
1852

    
1853
--
1854
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1855
--
1856

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

    
1859

    
1860
--
1861
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1862
--
1863

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

    
1866

    
1867
--
1868
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1869
--
1870

    
1871
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1872

    
1873

    
1874
--
1875
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1876
--
1877

    
1878
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();
1879

    
1880

    
1881
--
1882
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1883
--
1884

    
1885
ALTER TABLE ONLY batch
1886
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1887

    
1888

    
1889
--
1890
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1891
--
1892

    
1893
ALTER TABLE ONLY batch_download_settings
1894
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1895

    
1896

    
1897
--
1898
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1899
--
1900

    
1901
ALTER TABLE ONLY taxon_match
1902
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1903

    
1904

    
1905
--
1906
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1907
--
1908

    
1909
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1910
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1911
GRANT ALL ON SCHEMA "TNRS" TO bien;
1912
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1913

    
1914

    
1915
--
1916
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1917
--
1918

    
1919
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1920
REVOKE ALL ON TABLE taxon_match FROM bien;
1921
GRANT ALL ON TABLE taxon_match TO bien;
1922
GRANT SELECT ON TABLE taxon_match TO bien_read;
1923

    
1924

    
1925
--
1926
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1927
--
1928

    
1929
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1930
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1931
GRANT ALL ON TABLE taxon_best_match TO bien;
1932
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1933

    
1934

    
1935
--
1936
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1937
--
1938

    
1939
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
1940
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
1941
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
1942
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
1943

    
1944

    
1945
--
1946
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1947
--
1948

    
1949
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
1950
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
1951
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
1952
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
1953

    
1954

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

    
1959
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1960
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1961
GRANT ALL ON TABLE taxon_match_input TO bien;
1962
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1963

    
1964

    
1965
--
1966
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
1967
--
1968

    
1969
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
1970
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
1971
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
1972
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
1973

    
1974

    
1975
--
1976
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1977
--
1978

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

    
1984

    
1985
--
1986
-- PostgreSQL database dump complete
1987
--
1988

    
(7-7/9)