Project

General

Profile

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

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

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

    
16
--CREATE SCHEMA "TNRS";
17

    
18

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

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

    
41

    
42
SET search_path = "TNRS", pg_catalog;
43

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

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

    
58

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

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

    
69

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

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

    
80

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

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

    
94

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

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

    
105

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

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

    
114

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

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

    
128

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

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

    
196

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

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

    
209

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

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

    
328

    
329
--
330
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
331
--
332

    
333
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
334
autogenerated, do not edit
335

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

    
340

    
341
--
342
-- Name: taxon_match__match_num__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
343
--
344

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

    
356

    
357
--
358
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
359
--
360

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

    
367

    
368
--
369
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
370
--
371

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

    
381

    
382
--
383
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
384
--
385

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

    
392

    
393
--
394
-- Name: unsafe_taxon_names(); Type: FUNCTION; Schema: TNRS; Owner: -
395
--
396

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

    
404

    
405
SET default_tablespace = '';
406

    
407
SET default_with_oids = false;
408

    
409
--
410
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
411
--
412

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

    
570

    
571
--
572
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
573
--
574

    
575
COMMENT ON TABLE taxon_match IS '
576
whenever columns are renamed:
577
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
578

    
579
to port derived column changes to vegbiendev:
580
SELECT util.derived_cols_export(''"TNRS".taxon_match'');
581
# run the returned SQL on vegbiendev
582
	-- runtime: 30 min ("5564201 rows affected, 1624829 ms execution time")
583
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
584

    
585
to add a new derived column:
586
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''col''), $$
587
expr
588
$$));
589
SELECT util.derived_cols_populate(''"TNRS".taxon_match'');
590
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
591
$ make schemas/remake
592

    
593
to remove a column:
594
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
595
$ make schemas/remake
596

    
597
to move a derived column to the middle or to add a non-derived column:
598
make the changes in inputs/.TNRS/schema.sql
599
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS; runtime: 1 min ("1m2.629s")
600
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
601
SELECT util.derived_cols_repopulate(''"TNRS".taxon_match'');
602
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
603
$ make schemas/remake
604

    
605
to add a constraint: runtime: 3 min ("173620 ms")
606
';
607

    
608

    
609
--
610
-- Name: COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
611
--
612

    
613
COMMENT ON COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS '
614
= "*Unmatched_terms"
615

    
616
derived column
617

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

    
622
to rename:
623
# rename column
624
# rename CHECK constraint
625
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
626
';
627

    
628

    
629
--
630
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
631
--
632

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

    
636
derived column
637

    
638
to modify expr:
639
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);
640
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
641

    
642
to rename:
643
# rename column
644
# rename CHECK constraint
645
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
646
';
647

    
648

    
649
--
650
-- Name: COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
651
--
652

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

    
656
derived column
657

    
658
to modify expr:
659
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);
660
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
661

    
662
to rename:
663
# rename column
664
# rename CHECK constraint
665
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
666
';
667

    
668

    
669
--
670
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
671
--
672

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

    
676
derived column
677

    
678
to modify expr:
679
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);
680
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
681

    
682
to rename:
683
# rename column
684
# rename CHECK constraint
685
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
686
';
687

    
688

    
689
--
690
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
691
--
692

    
693
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
694
= "*Accepted_name" IS NOT NULL
695

    
696
derived column
697

    
698
to modify expr:
699
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
700
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
701

    
702
to rename:
703
# rename column
704
# rename CHECK constraint
705
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
706
';
707

    
708

    
709
--
710
-- Name: COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
711
--
712

    
713
COMMENT ON COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org" IS '
714
= COALESCE("*Accepted_name_family",
715
CASE
716
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
717
    ELSE NULL::text
718
END)
719

    
720
derived column
721

    
722
to modify expr:
723
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col, $$COALESCE("*Accepted_name_family",
724
CASE
725
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
726
    ELSE NULL::text
727
END)$$)::util.derived_col_def);
728
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
729

    
730
to rename:
731
# rename column
732
# rename CHECK constraint
733
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
734
';
735

    
736

    
737
--
738
-- Name: COLUMN taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
739
--
740

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

    
744
derived column
745

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

    
750
to rename:
751
# rename column
752
# rename CHECK constraint
753
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
754
';
755

    
756

    
757
--
758
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
759
--
760

    
761
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet}" IS '
762
= regexp_split_to_array("Accepted_species[_binomial]__@TNRS__@vegpath.org", '' ''::text)
763

    
764
derived column
765

    
766
to modify expr:
767
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet}'')::util.col, $$regexp_split_to_array("Accepted_species[_binomial]__@TNRS__@vegpath.org", '' ''::text)$$)::util.derived_col_def);
768
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
769

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

    
776

    
777
--
778
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
779
--
780

    
781
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
782
= COALESCE("__accepted_{genus,specific_epithet}"[1],
783
CASE
784
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN "*Accepted_name"
785
    ELSE NULL::text
786
END)
787

    
788
derived column
789

    
790
to modify expr:
791
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$COALESCE("__accepted_{genus,specific_epithet}"[1],
792
CASE
793
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN "*Accepted_name"
794
    ELSE NULL::text
795
END)$$)::util.derived_col_def);
796
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
797

    
798
to rename:
799
# rename column
800
# rename CHECK constraint
801
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
802
';
803

    
804

    
805
--
806
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
807
--
808

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

    
812
derived column
813

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

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

    
824

    
825
--
826
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
827
--
828

    
829
COMMENT ON COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
830
= CASE
831
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
832
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
833
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
834
END
835

    
836
derived column
837

    
838
to modify expr:
839
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
840
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
841
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
842
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
843
END$$)::util.derived_col_def);
844
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
845

    
846
to rename:
847
# rename column
848
# rename CHECK constraint
849
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
850
';
851

    
852

    
853
--
854
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
855
--
856

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

    
860
derived column
861

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

    
866
to rename:
867
# rename column
868
# rename CHECK constraint
869
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
870
';
871

    
872

    
873
--
874
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
875
--
876

    
877
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
878
= regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
879

    
880
derived column
881

    
882
to modify expr:
883
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);
884
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
885

    
886
to rename:
887
# rename column
888
# rename CHECK constraint
889
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
890
';
891

    
892

    
893
--
894
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
895
--
896

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

    
900
derived column
901

    
902
to modify expr:
903
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);
904
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
905

    
906
to rename:
907
# rename column
908
# rename CHECK constraint
909
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
910
';
911

    
912

    
913
--
914
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
915
--
916

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

    
920
derived column
921

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

    
926
to rename:
927
# rename column
928
# rename CHECK constraint
929
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
930
';
931

    
932

    
933
--
934
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
935
--
936

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

    
940
derived column
941

    
942
to modify expr:
943
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);
944
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
945

    
946
to rename:
947
# rename column
948
# rename CHECK constraint
949
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
950
';
951

    
952

    
953
--
954
-- Name: COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
955
--
956

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

    
960
derived column
961

    
962
to modify expr:
963
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);
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_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
975
--
976

    
977
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
978
= CASE
979
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
980
    ELSE "*Name_matched_rank"
981
END
982

    
983
derived column
984

    
985
to modify expr:
986
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
987
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
988
    ELSE "*Name_matched_rank"
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_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1001
--
1002

    
1003
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1004
= CASE
1005
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
1006
    ELSE "*Name_matched_accepted_family"
1007
END
1008

    
1009
derived column
1010

    
1011
to modify expr:
1012
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1013
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
1014
    ELSE "*Name_matched_accepted_family"
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_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1027
--
1028

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

    
1035
derived column
1036

    
1037
to modify expr:
1038
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
1039
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1040
    ELSE "*Genus_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_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1053
--
1054

    
1055
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
1056
= CASE
1057
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1058
    ELSE "*Specific_epithet_matched"
1059
END
1060

    
1061
derived column
1062

    
1063
to modify expr:
1064
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1065
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1066
    ELSE "*Specific_epithet_matched"
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_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1079
--
1080

    
1081
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1082
= CASE
1083
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1084
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1085
END
1086

    
1087
derived column
1088

    
1089
to modify expr:
1090
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1091
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1092
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1093
END$$)::util.derived_col_def);
1094
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1095

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

    
1102

    
1103
--
1104
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1105
--
1106

    
1107
COMMENT ON COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
1108
= CASE
1109
    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")
1110
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1111
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1112
END
1113

    
1114
derived column
1115

    
1116
to modify expr:
1117
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
1118
    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")
1119
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1120
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
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_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1133
--
1134

    
1135
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1136
= CASE
1137
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1138
    ELSE "*Infraspecific_rank"
1139
END
1140

    
1141
derived column
1142

    
1143
to modify expr:
1144
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$CASE
1145
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1146
    ELSE "*Infraspecific_rank"
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_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1159
--
1160

    
1161
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1162
= CASE
1163
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1164
    ELSE "*Infraspecific_epithet_matched"
1165
END
1166

    
1167
derived column
1168

    
1169
to modify expr:
1170
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1171
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1172
    ELSE "*Infraspecific_epithet_matched"
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_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1185
--
1186

    
1187
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1188
= CASE
1189
    WHEN matched_has_accepted THEN "*Accepted_name"
1190
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1191
END
1192

    
1193
derived column
1194

    
1195
to modify expr:
1196
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1197
    WHEN matched_has_accepted THEN "*Accepted_name"
1198
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
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_]author~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1211
--
1212

    
1213
COMMENT ON COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1214
= CASE
1215
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1216
    ELSE "*Name_matched_author"
1217
END
1218

    
1219
derived column
1220

    
1221
to modify expr:
1222
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1223
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1224
    ELSE "*Name_matched_author"
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: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1237
--
1238

    
1239
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1240
= CASE
1241
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1242
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1243
END
1244

    
1245
derived column
1246

    
1247
to modify expr:
1248
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$CASE
1249
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1250
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1251
END$$)::util.derived_col_def);
1252
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1253

    
1254
to rename:
1255
# rename column
1256
# rename CHECK constraint
1257
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1258
';
1259

    
1260

    
1261
--
1262
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1263
--
1264

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

    
1337

    
1338
--
1339
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1340
--
1341

    
1342
COMMENT ON VIEW taxon_best_match IS '
1343
to modify:
1344
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1345
SELECT __
1346
$$);
1347
';
1348

    
1349

    
1350
--
1351
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1352
--
1353

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

    
1431

    
1432
--
1433
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1434
--
1435

    
1436
COMMENT ON VIEW "MatchedTaxon" IS '
1437
to modify:
1438
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
1439
SELECT __
1440
$$);
1441
';
1442

    
1443

    
1444
--
1445
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1446
--
1447

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

    
1522

    
1523
--
1524
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1525
--
1526

    
1527
COMMENT ON VIEW "ValidMatchedTaxon" IS '
1528
to update, use * as the column list
1529
';
1530

    
1531

    
1532
--
1533
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1534
--
1535

    
1536
CREATE TABLE batch (
1537
    id text NOT NULL,
1538
    id_by_time text,
1539
    time_submitted timestamp with time zone DEFAULT now(),
1540
    client_version text
1541
);
1542

    
1543

    
1544
--
1545
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1546
--
1547

    
1548
CREATE TABLE batch_download_settings (
1549
    id text NOT NULL,
1550
    "E-mail" text,
1551
    "Id" text,
1552
    "Job type" text,
1553
    "Contains Id" boolean,
1554
    "Start time" text,
1555
    "Finish time" text,
1556
    "TNRS version" text,
1557
    "Sources selected" text,
1558
    "Match threshold" double precision,
1559
    "Classification" text,
1560
    "Allow partial matches?" boolean,
1561
    "Sort by source" boolean,
1562
    "Constrain by higher taxonomy" boolean
1563
);
1564

    
1565

    
1566
--
1567
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
1568
--
1569

    
1570
COMMENT ON TABLE batch_download_settings IS '
1571
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
1572
';
1573

    
1574

    
1575
--
1576
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1577
--
1578

    
1579
CREATE TABLE client_version (
1580
    id text NOT NULL,
1581
    global_rev integer NOT NULL,
1582
    "/lib/tnrs.py rev" integer,
1583
    "/bin/tnrs_db rev" integer
1584
);
1585

    
1586

    
1587
--
1588
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
1589
--
1590

    
1591
COMMENT ON TABLE client_version IS '
1592
contains svn revisions
1593
';
1594

    
1595

    
1596
--
1597
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
1598
--
1599

    
1600
COMMENT ON COLUMN client_version.global_rev IS '
1601
from `svn info .` > Last Changed Rev
1602
';
1603

    
1604

    
1605
--
1606
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
1607
--
1608

    
1609
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
1610
from `svn info lib/tnrs.py` > Last Changed Rev
1611
';
1612

    
1613

    
1614
--
1615
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
1616
--
1617

    
1618
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
1619
from `svn info bin/tnrs_db` > Last Changed Rev
1620
';
1621

    
1622

    
1623
--
1624
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1625
--
1626

    
1627
CREATE VIEW taxon_match_input AS
1628
 SELECT taxon_match."*Name_number" AS "Name_number",
1629
    taxon_match."*Name_submitted" AS "Name_submitted",
1630
    taxon_match."*Overall_score" AS "Overall_score",
1631
    taxon_match."*Name_matched" AS "Name_matched",
1632
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1633
    taxon_match."*Name_score" AS "Name_score",
1634
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1635
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1636
    taxon_match."*Author_matched" AS "Author_matched",
1637
    taxon_match."*Author_score" AS "Author_score",
1638
    taxon_match."*Family_matched" AS "Family_matched",
1639
    taxon_match."*Family_score" AS "Family_score",
1640
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1641
    taxon_match."*Genus_matched" AS "Genus_matched",
1642
    taxon_match."*Genus_score" AS "Genus_score",
1643
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1644
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1645
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1646
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1647
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1648
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1649
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1650
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1651
    taxon_match."*Annotations" AS "Annotations",
1652
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1653
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1654
    taxon_match."*Accepted_name" AS "Accepted_name",
1655
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1656
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1657
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1658
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1659
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1660
    taxon_match."*Selected" AS "Selected",
1661
    taxon_match."*Source" AS "Source",
1662
    taxon_match."*Warnings" AS "Warnings",
1663
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1664
   FROM taxon_match;
1665

    
1666

    
1667
--
1668
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1669
--
1670

    
1671
CREATE TABLE taxon_match_input__copy_to (
1672
    "Name_number" integer,
1673
    "Name_submitted" text,
1674
    "Overall_score" double precision,
1675
    "Name_matched" text,
1676
    "Name_matched_rank" text,
1677
    "Name_score" double precision,
1678
    "Name_matched_author" text,
1679
    "Name_matched_url" text,
1680
    "Author_matched" text,
1681
    "Author_score" double precision,
1682
    "Family_matched" text,
1683
    "Family_score" double precision,
1684
    "Name_matched_accepted_family" text,
1685
    "Genus_matched" text,
1686
    "Genus_score" double precision,
1687
    "Specific_epithet_matched" text,
1688
    "Specific_epithet_score" double precision,
1689
    "Infraspecific_rank" text,
1690
    "Infraspecific_epithet_matched" text,
1691
    "Infraspecific_epithet_score" double precision,
1692
    "Infraspecific_rank_2" text,
1693
    "Infraspecific_epithet_2_matched" text,
1694
    "Infraspecific_epithet_2_score" double precision,
1695
    "Annotations" text,
1696
    "Unmatched_terms" text,
1697
    "Taxonomic_status" text,
1698
    "Accepted_name" text,
1699
    "Accepted_name_author" text,
1700
    "Accepted_name_rank" text,
1701
    "Accepted_name_url" text,
1702
    "Accepted_name_species" text,
1703
    "Accepted_name_family" text,
1704
    "Selected" text,
1705
    "Source" text,
1706
    "Warnings" text,
1707
    "Accepted_name_lsid" text
1708
);
1709

    
1710

    
1711
--
1712
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
1713
--
1714

    
1715
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
1716
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
1717
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
1718
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
1719
    taxon_match."*Genus_matched" AS scrubbed_genus,
1720
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
1721
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
1722
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
1723
    taxon_match."*Name_matched_author" AS scrubbed_author,
1724
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
1725
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
1726
   FROM taxon_match;
1727

    
1728

    
1729
--
1730
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1731
--
1732

    
1733
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1734
to modify:
1735
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1736
SELECT __
1737
$$);
1738

    
1739
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.
1740
';
1741

    
1742

    
1743
--
1744
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1745
--
1746

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

    
1835

    
1836
--
1837
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1838
--
1839

    
1840
COMMENT ON VIEW taxon_scrub IS '
1841
to modify:
1842
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1843
SELECT __
1844
$$);
1845
';
1846

    
1847

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

    
1852
ALTER TABLE ONLY batch_download_settings
1853
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1854

    
1855

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

    
1860
ALTER TABLE ONLY batch
1861
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1862

    
1863

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

    
1868
ALTER TABLE ONLY batch
1869
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1870

    
1871

    
1872
--
1873
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1874
--
1875

    
1876
ALTER TABLE ONLY client_version
1877
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1878

    
1879

    
1880
--
1881
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1882
--
1883

    
1884
ALTER TABLE ONLY taxon_match
1885
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1886

    
1887
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1888

    
1889

    
1890
--
1891
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1892
--
1893

    
1894
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1895

    
1896

    
1897
--
1898
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1899
--
1900

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

    
1903

    
1904
--
1905
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1906
--
1907

    
1908
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1909

    
1910

    
1911
--
1912
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1913
--
1914

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

    
1917

    
1918
--
1919
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1920
--
1921

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

    
1924

    
1925
--
1926
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1927
--
1928

    
1929
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1930

    
1931

    
1932
--
1933
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1934
--
1935

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

    
1938

    
1939
--
1940
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1941
--
1942

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

    
1945

    
1946
--
1947
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1948
--
1949

    
1950
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1951

    
1952

    
1953
--
1954
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1955
--
1956

    
1957
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();
1958

    
1959

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

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

    
1967

    
1968
--
1969
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1970
--
1971

    
1972
ALTER TABLE ONLY batch_download_settings
1973
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1974

    
1975

    
1976
--
1977
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1978
--
1979

    
1980
ALTER TABLE ONLY taxon_match
1981
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1982

    
1983

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

    
1988
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1989
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1990
GRANT ALL ON SCHEMA "TNRS" TO bien;
1991
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1992

    
1993

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

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

    
2003

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

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

    
2013

    
2014
--
2015
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
2016
--
2017

    
2018
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
2019
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
2020
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
2021
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
2022

    
2023

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

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

    
2033

    
2034
--
2035
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
2036
--
2037

    
2038
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
2039
REVOKE ALL ON TABLE taxon_match_input FROM bien;
2040
GRANT ALL ON TABLE taxon_match_input TO bien;
2041
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
2042

    
2043

    
2044
--
2045
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
2046
--
2047

    
2048
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
2049
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
2050
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
2051
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
2052

    
2053

    
2054
--
2055
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
2056
--
2057

    
2058
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
2059
REVOKE ALL ON TABLE taxon_scrub FROM bien;
2060
GRANT ALL ON TABLE taxon_scrub TO bien;
2061
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
2062

    
2063

    
2064
--
2065
-- PostgreSQL database dump complete
2066
--
2067

    
(7-7/9)