Project

General

Profile

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

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

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

    
16
--CREATE SCHEMA "TNRS";
17

    
18

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

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

    
41

    
42
SET search_path = "TNRS", pg_catalog;
43

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

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

    
58

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

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

    
69

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

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

    
80

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

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

    
94

    
95
--
96
-- Name: taxon_match__batch_begin(); Type: FUNCTION; Schema: TNRS; Owner: -
97
--
98

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

    
108

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

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

    
176

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

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

    
189

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

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

    
306

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

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

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

    
318

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

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

    
334

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

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

    
345

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

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

    
359

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

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

    
370

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

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

    
382

    
383
SET default_tablespace = '';
384

    
385
SET default_with_oids = false;
386

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

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

    
546

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

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

    
555
to port derived column changes to vegbiendev:
556
SELECT util.derived_cols_export(''"TNRS".taxon_match'');
557
# run the returned SQL on vegbiendev
558

    
559
to remove columns or add columns at the end:
560
$ rm=1 inputs/.TNRS/data.sql.run
561
$ make schemas/remake
562

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

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

    
578
to add a constraint: runtime: 3 min ("173620 ms")
579
';
580

    
581

    
582
--
583
-- Name: COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
584
--
585

    
586
COMMENT ON COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS '
587
= "*Unmatched_terms"
588

    
589
derived column
590

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

    
595
to rename:
596
# rename column
597
# rename CHECK constraint
598
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
599
';
600

    
601

    
602
--
603
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
604
--
605

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

    
609
derived column
610

    
611
to modify expr:
612
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);
613
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
614

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

    
621

    
622
--
623
-- Name: COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
624
--
625

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

    
629
derived column
630

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

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

    
641

    
642
--
643
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
644
--
645

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

    
649
derived column
650

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

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

    
661

    
662
--
663
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
664
--
665

    
666
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
667
= "*Accepted_name" IS NOT NULL
668

    
669
derived column
670

    
671
to modify expr:
672
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
673
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
674

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

    
681

    
682
--
683
-- Name: COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
684
--
685

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

    
693
derived column
694

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

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

    
709

    
710
--
711
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
712
--
713

    
714
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet}" IS '
715
= regexp_split_to_array("*Accepted_name_species", '' ''::text)
716

    
717
derived column
718

    
719
to modify expr:
720
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet}'')::util.col, $$regexp_split_to_array("*Accepted_name_species", '' ''::text)$$)::util.derived_col_def);
721
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
722

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

    
729

    
730
--
731
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
732
--
733

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

    
741
derived column
742

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

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

    
757

    
758
--
759
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
760
--
761

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

    
765
derived column
766

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

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

    
777

    
778
--
779
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
780
--
781

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

    
789
derived column
790

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

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

    
805

    
806
--
807
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
808
--
809

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

    
813
derived column
814

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

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

    
825

    
826
--
827
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
828
--
829

    
830
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
831
= regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
832

    
833
derived column
834

    
835
to modify expr:
836
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);
837
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
838

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

    
845

    
846
--
847
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
848
--
849

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

    
853
derived column
854

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

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

    
865

    
866
--
867
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
868
--
869

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

    
873
derived column
874

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

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

    
885

    
886
--
887
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
888
--
889

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

    
893
derived column
894

    
895
to modify expr:
896
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);
897
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
898

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

    
905

    
906
--
907
-- Name: COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
908
--
909

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

    
913
derived column
914

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

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

    
925

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

    
930
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
931
= CASE
932
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
933
    ELSE "*Name_matched_rank"
934
END
935

    
936
derived column
937

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

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

    
951

    
952
--
953
-- Name: COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
954
--
955

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

    
962
derived column
963

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

    
971
to rename:
972
# rename column
973
# rename CHECK constraint
974
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
975
';
976

    
977

    
978
--
979
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
980
--
981

    
982
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
983
= CASE
984
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
985
    ELSE "*Genus_matched"
986
END
987

    
988
derived column
989

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

    
997
to rename:
998
# rename column
999
# rename CHECK constraint
1000
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1001
';
1002

    
1003

    
1004
--
1005
-- Name: COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1006
--
1007

    
1008
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
1009
= CASE
1010
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1011
    ELSE "*Specific_epithet_matched"
1012
END
1013

    
1014
derived column
1015

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

    
1023
to rename:
1024
# rename column
1025
# rename CHECK constraint
1026
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1027
';
1028

    
1029

    
1030
--
1031
-- Name: COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1032
--
1033

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

    
1040
derived column
1041

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

    
1049
to rename:
1050
# rename column
1051
# rename CHECK constraint
1052
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1053
';
1054

    
1055

    
1056
--
1057
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1058
--
1059

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

    
1067
derived column
1068

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

    
1077
to rename:
1078
# rename column
1079
# rename CHECK constraint
1080
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1081
';
1082

    
1083

    
1084
--
1085
-- Name: COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1086
--
1087

    
1088
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1089
= CASE
1090
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1091
    ELSE "*Infraspecific_rank"
1092
END
1093

    
1094
derived column
1095

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

    
1103
to rename:
1104
# rename column
1105
# rename CHECK constraint
1106
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1107
';
1108

    
1109

    
1110
--
1111
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1112
--
1113

    
1114
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1115
= CASE
1116
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1117
    ELSE "*Infraspecific_epithet_matched"
1118
END
1119

    
1120
derived column
1121

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

    
1129
to rename:
1130
# rename column
1131
# rename CHECK constraint
1132
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1133
';
1134

    
1135

    
1136
--
1137
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1138
--
1139

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

    
1146
derived column
1147

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

    
1155
to rename:
1156
# rename column
1157
# rename CHECK constraint
1158
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1159
';
1160

    
1161

    
1162
--
1163
-- Name: COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1164
--
1165

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

    
1172
derived column
1173

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

    
1181
to rename:
1182
# rename column
1183
# rename CHECK constraint
1184
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1185
';
1186

    
1187

    
1188
--
1189
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1190
--
1191

    
1192
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1193
= CASE
1194
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1195
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1196
END
1197

    
1198
derived column
1199

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

    
1207
to rename:
1208
# rename column
1209
# rename CHECK constraint
1210
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1211
';
1212

    
1213

    
1214
--
1215
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1216
--
1217

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

    
1283

    
1284
--
1285
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1286
--
1287

    
1288
COMMENT ON VIEW taxon_best_match IS '
1289
to modify:
1290
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1291
SELECT __
1292
$$);
1293
';
1294

    
1295

    
1296
--
1297
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1298
--
1299

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

    
1370

    
1371
--
1372
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1373
--
1374

    
1375
COMMENT ON VIEW "MatchedTaxon" IS '
1376
to modify:
1377
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
1378
SELECT __
1379
$$);
1380
';
1381

    
1382

    
1383
--
1384
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1385
--
1386

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

    
1454

    
1455
--
1456
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1457
--
1458

    
1459
COMMENT ON VIEW "ValidMatchedTaxon" IS '
1460
to update, use * as the column list
1461
';
1462

    
1463

    
1464
--
1465
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1466
--
1467

    
1468
CREATE TABLE batch (
1469
    id text NOT NULL,
1470
    id_by_time text,
1471
    time_submitted timestamp with time zone DEFAULT now(),
1472
    client_version text
1473
);
1474

    
1475

    
1476
--
1477
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1478
--
1479

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

    
1497

    
1498
--
1499
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
1500
--
1501

    
1502
COMMENT ON TABLE batch_download_settings IS '
1503
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
1504
';
1505

    
1506

    
1507
--
1508
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1509
--
1510

    
1511
CREATE TABLE client_version (
1512
    id text NOT NULL,
1513
    global_rev integer NOT NULL,
1514
    "/lib/tnrs.py rev" integer,
1515
    "/bin/tnrs_db rev" integer
1516
);
1517

    
1518

    
1519
--
1520
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
1521
--
1522

    
1523
COMMENT ON TABLE client_version IS '
1524
contains svn revisions
1525
';
1526

    
1527

    
1528
--
1529
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
1530
--
1531

    
1532
COMMENT ON COLUMN client_version.global_rev IS '
1533
from `svn info .` > Last Changed Rev
1534
';
1535

    
1536

    
1537
--
1538
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
1539
--
1540

    
1541
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
1542
from `svn info lib/tnrs.py` > Last Changed Rev
1543
';
1544

    
1545

    
1546
--
1547
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
1548
--
1549

    
1550
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
1551
from `svn info bin/tnrs_db` > Last Changed Rev
1552
';
1553

    
1554

    
1555
--
1556
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1557
--
1558

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

    
1598

    
1599
--
1600
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1601
--
1602

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

    
1642

    
1643
--
1644
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
1645
--
1646

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

    
1660

    
1661
--
1662
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1663
--
1664

    
1665
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1666
to modify:
1667
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1668
SELECT __
1669
$$);
1670

    
1671
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.
1672
';
1673

    
1674

    
1675
--
1676
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1677
--
1678

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

    
1760

    
1761
--
1762
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1763
--
1764

    
1765
COMMENT ON VIEW taxon_scrub IS '
1766
to modify:
1767
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1768
SELECT __
1769
$$);
1770
';
1771

    
1772

    
1773
--
1774
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1775
--
1776

    
1777
ALTER TABLE ONLY batch_download_settings
1778
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1779

    
1780

    
1781
--
1782
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1783
--
1784

    
1785
ALTER TABLE ONLY batch
1786
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1787

    
1788

    
1789
--
1790
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1791
--
1792

    
1793
ALTER TABLE ONLY batch
1794
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1795

    
1796

    
1797
--
1798
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1799
--
1800

    
1801
ALTER TABLE ONLY client_version
1802
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1803

    
1804

    
1805
--
1806
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1807
--
1808

    
1809
ALTER TABLE ONLY taxon_match
1810
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1811

    
1812
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1813

    
1814

    
1815
--
1816
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1817
--
1818

    
1819
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1820

    
1821

    
1822
--
1823
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1824
--
1825

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

    
1828

    
1829
--
1830
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1831
--
1832

    
1833
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1834

    
1835

    
1836
--
1837
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1838
--
1839

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

    
1842

    
1843
--
1844
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1845
--
1846

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

    
1849

    
1850
--
1851
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1852
--
1853

    
1854
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1855

    
1856

    
1857
--
1858
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1859
--
1860

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

    
1863

    
1864
--
1865
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1866
--
1867

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

    
1870

    
1871
--
1872
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1873
--
1874

    
1875
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1876

    
1877

    
1878
--
1879
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1880
--
1881

    
1882
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();
1883

    
1884

    
1885
--
1886
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1887
--
1888

    
1889
ALTER TABLE ONLY batch
1890
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1891

    
1892

    
1893
--
1894
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1895
--
1896

    
1897
ALTER TABLE ONLY batch_download_settings
1898
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1899

    
1900

    
1901
--
1902
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1903
--
1904

    
1905
ALTER TABLE ONLY taxon_match
1906
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1907

    
1908

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

    
1913
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1914
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1915
GRANT ALL ON SCHEMA "TNRS" TO bien;
1916
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1917

    
1918

    
1919
--
1920
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1921
--
1922

    
1923
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1924
REVOKE ALL ON TABLE taxon_match FROM bien;
1925
GRANT ALL ON TABLE taxon_match TO bien;
1926
GRANT SELECT ON TABLE taxon_match TO bien_read;
1927

    
1928

    
1929
--
1930
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1931
--
1932

    
1933
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1934
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1935
GRANT ALL ON TABLE taxon_best_match TO bien;
1936
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1937

    
1938

    
1939
--
1940
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1941
--
1942

    
1943
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
1944
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
1945
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
1946
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
1947

    
1948

    
1949
--
1950
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1951
--
1952

    
1953
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
1954
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
1955
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
1956
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
1957

    
1958

    
1959
--
1960
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
1961
--
1962

    
1963
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1964
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1965
GRANT ALL ON TABLE taxon_match_input TO bien;
1966
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1967

    
1968

    
1969
--
1970
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
1971
--
1972

    
1973
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
1974
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
1975
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
1976
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
1977

    
1978

    
1979
--
1980
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1981
--
1982

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

    
1988

    
1989
--
1990
-- PostgreSQL database dump complete
1991
--
1992

    
(7-7/9)