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
	new."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT
199
		("*Genus_matched" || ' '::text) || "*Specific_epithet_matched"
200
		FROM (SELECT new.*) new);
201
	
202
	new."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT
203
		"*Name_matched" || COALESCE((' '::text || "*Name_matched_author"), ''::text)
204
		FROM (SELECT new.*) new);
205
	
206
	new.matched_has_accepted = (SELECT
207
		"*Accepted_name" IS NOT NULL
208
		FROM (SELECT new.*) new);
209
	
210
	new."__accepted_{genus,specific_epithet}" = (SELECT
211
		regexp_split_to_array("*Accepted_name_species", ' '::text)
212
		FROM (SELECT new.*) new);
213
	
214
	new."[accepted_]genus__@DwC__@vegpath.org" = (SELECT
215
		"__accepted_{genus,specific_epithet}"[1]
216
		FROM (SELECT new.*) new);
217
	
218
	new."[accepted_]specificEpithet__@DwC__@vegpath.org" = (SELECT
219
		"__accepted_{genus,specific_epithet}"[2]
220
		FROM (SELECT new.*) new);
221
	
222
	new.__accepted_infraspecific_label = (SELECT
223
		ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''::text), ' '::text)
224
		FROM (SELECT new.*) new);
225
	
226
	new."__accepted_infraspecific_{rank,epithet}" = (SELECT
227
		regexp_split_to_array(__accepted_infraspecific_label, ' '::text)
228
		FROM (SELECT new.*) new);
229
	
230
	new."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = (SELECT
231
		"__accepted_infraspecific_{rank,epithet}"[1]
232
		FROM (SELECT new.*) new);
233
	
234
	new."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" = (SELECT
235
		"__accepted_infraspecific_{rank,epithet}"[2]
236
		FROM (SELECT new.*) new);
237
	
238
	new."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT
239
		"*Accepted_name" || COALESCE((' '::text || "*Accepted_name_author"), ''::text)
240
		FROM (SELECT new.*) new);
241
	
242
	new."[scrubbed_]taxonRank__@DwC__@vegpath.org" = (SELECT
243
		CASE
244
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
245
    ELSE "*Name_matched_rank"
246
END
247
		FROM (SELECT new.*) new);
248
	
249
	new."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT
250
		CASE
251
    WHEN matched_has_accepted THEN "*Accepted_name_family"
252
    ELSE "*Name_matched_accepted_family"
253
END
254
		FROM (SELECT new.*) new);
255
	
256
	new."[scrubbed_]genus__@DwC__@vegpath.org" = (SELECT
257
		CASE
258
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
259
    ELSE "*Genus_matched"
260
END
261
		FROM (SELECT new.*) new);
262
	
263
	new."[scrubbed_]specificEpithet__@DwC__@vegpath.org" = (SELECT
264
		CASE
265
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
266
    ELSE "*Specific_epithet_matched"
267
END
268
		FROM (SELECT new.*) new);
269
	
270
	new."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT
271
		CASE
272
    WHEN matched_has_accepted THEN "*Accepted_name_species"
273
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
274
END
275
		FROM (SELECT new.*) new);
276
	
277
	new."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = (SELECT
278
		CASE
279
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
280
    ELSE "*Infraspecific_rank"
281
END
282
		FROM (SELECT new.*) new);
283
	
284
	new."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" = (SELECT
285
		CASE
286
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
287
    ELSE "*Infraspecific_epithet_matched"
288
END
289
		FROM (SELECT new.*) new);
290
	
291
	new."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT
292
		CASE
293
    WHEN matched_has_accepted THEN "*Accepted_name"
294
    ELSE "*Name_matched"
295
END
296
		FROM (SELECT new.*) new);
297
	
298
	new."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT
299
		CASE
300
    WHEN matched_has_accepted THEN "*Accepted_name_author"
301
    ELSE "*Name_matched_author"
302
END
303
		FROM (SELECT new.*) new);
304
	
305
	new."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT
306
		CASE
307
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
308
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
309
END
310
		FROM (SELECT new.*) new);
311
	
312
	RETURN new;
313
END;
314
$$;
315

    
316

    
317
--
318
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
319
--
320

    
321
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
322
autogenerated, do not edit
323

    
324
to regenerate:
325
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
326
';
327

    
328

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

    
333
CREATE FUNCTION taxon_match__match_num__fill() RETURNS trigger
334
    LANGUAGE plpgsql
335
    AS $$
336
BEGIN
337
	IF new.match_num IS NULL THEN
338
		new.match_num = "TNRS".taxon_match__match_num__next();
339
	END IF;
340
	RETURN new;
341
END;
342
$$;
343

    
344

    
345
--
346
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
347
--
348

    
349
CREATE FUNCTION taxon_match__match_num__next() RETURNS bigint
350
    LANGUAGE sql
351
    AS $$
352
SELECT nextval('pg_temp.taxon_match__match_num__seq');
353
$$;
354

    
355

    
356
--
357
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
358
--
359

    
360
CREATE FUNCTION taxon_match_input__copy_to__insert() RETURNS trigger
361
    LANGUAGE plpgsql
362
    AS $$
363
BEGIN
364
	INSERT INTO "TNRS".taxon_match_input SELECT new.*;
365
	RETURN NULL;
366
END;
367
$$;
368

    
369

    
370
--
371
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
372
--
373

    
374
CREATE FUNCTION taxon_name_is_safe(taxon_name text) RETURNS boolean
375
    LANGUAGE sql IMMUTABLE
376
    AS $_$
377
SELECT NOT ($1 = ANY("TNRS".unsafe_taxon_names()))
378
$_$;
379

    
380

    
381
--
382
-- Name: unsafe_taxon_names(); Type: FUNCTION; Schema: TNRS; Owner: -
383
--
384

    
385
CREATE FUNCTION unsafe_taxon_names() RETURNS text[]
386
    LANGUAGE sql IMMUTABLE
387
    AS $$
388
SELECT ARRAY[
389
]::text[]
390
$$;
391

    
392

    
393
SET default_tablespace = '';
394

    
395
SET default_with_oids = false;
396

    
397
--
398
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
399
--
400

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

    
526

    
527
--
528
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
529
--
530

    
531
COMMENT ON TABLE taxon_match IS '
532
whenever columns are renamed:
533
SELECT util.derived_cols_sync(''"TNRS".taxon_match'');
534

    
535
to remove columns or add columns at the end:
536
$ rm=1 inputs/.TNRS/data.sql.run
537
$ make schemas/remake
538

    
539
to add columns in the middle:
540
make the changes in inputs/.TNRS/schema.sql
541
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS
542
$ make schemas/remake
543

    
544
to populate a new column:
545
ALTER TABLE "TNRS".taxon_match DISABLE TRIGGER taxon_match__fill; --speeds up update
546
UPDATE "TNRS".taxon_match SET "col" = value;
547
	-- runtime: 30 min ("5564201 rows affected, 1624829 ms execution time")
548
CLUSTER "TNRS".taxon_match; -- ensure rows are exported in sorted order
549
ALTER TABLE "TNRS".taxon_match ENABLE TRIGGER taxon_match__fill;
550
VACUUM ANALYZE "TNRS".taxon_match --remove previous rows; runtime: 1.5 min ("92633 ms")
551

    
552
to add a constraint: runtime: 3 min ("173620 ms")
553
';
554

    
555

    
556
--
557
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
558
--
559

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

    
563
derived column
564

    
565
to modify expr:
566
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);
567
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
568

    
569
to rename:
570
# rename column
571
# rename CHECK constraint
572
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
573
';
574

    
575

    
576
--
577
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
578
--
579

    
580
COMMENT ON COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
581
= "*Name_matched" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)
582

    
583
derived column
584

    
585
to modify expr:
586
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"*Name_matched" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)$$)::util.derived_col_def);
587
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
588

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

    
595

    
596
--
597
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
598
--
599

    
600
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
601
= "*Accepted_name" IS NOT NULL
602

    
603
derived column
604

    
605
to modify expr:
606
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
607
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
608

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

    
615

    
616
--
617
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
618
--
619

    
620
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet}" IS '
621
= regexp_split_to_array("*Accepted_name_species", '' ''::text)
622

    
623
derived column
624

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

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

    
635

    
636
--
637
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
638
--
639

    
640
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
641
= "__accepted_{genus,specific_epithet}"[1]
642

    
643
derived column
644

    
645
to modify expr:
646
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet}"[1]$$)::util.derived_col_def);
647
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
648

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

    
655

    
656
--
657
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
658
--
659

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

    
663
derived column
664

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

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

    
675

    
676
--
677
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
678
--
679

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

    
683
derived column
684

    
685
to modify expr:
686
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);
687
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
688

    
689
to rename:
690
# rename column
691
# rename CHECK constraint
692
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
693
';
694

    
695

    
696
--
697
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
698
--
699

    
700
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
701
= regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
702

    
703
derived column
704

    
705
to modify expr:
706
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);
707
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
708

    
709
to rename:
710
# rename column
711
# rename CHECK constraint
712
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
713
';
714

    
715

    
716
--
717
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
718
--
719

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

    
723
derived column
724

    
725
to modify expr:
726
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);
727
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
728

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

    
735

    
736
--
737
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
738
--
739

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

    
743
derived column
744

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

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

    
755

    
756
--
757
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
758
--
759

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

    
763
derived column
764

    
765
to modify expr:
766
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);
767
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
768

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

    
775

    
776
--
777
-- Name: COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
778
--
779

    
780
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
781
= CASE
782
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
783
    ELSE "*Name_matched_rank"
784
END
785

    
786
derived column
787

    
788
to modify expr:
789
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
790
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
791
    ELSE "*Name_matched_rank"
792
END$$)::util.derived_col_def);
793
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
794

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

    
801

    
802
--
803
-- Name: COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
804
--
805

    
806
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
807
= CASE
808
    WHEN matched_has_accepted THEN "*Accepted_name_family"
809
    ELSE "*Name_matched_accepted_family"
810
END
811

    
812
derived column
813

    
814
to modify expr:
815
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
816
    WHEN matched_has_accepted THEN "*Accepted_name_family"
817
    ELSE "*Name_matched_accepted_family"
818
END$$)::util.derived_col_def);
819
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
820

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

    
827

    
828
--
829
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
830
--
831

    
832
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
833
= CASE
834
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
835
    ELSE "*Genus_matched"
836
END
837

    
838
derived column
839

    
840
to modify expr:
841
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
842
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
843
    ELSE "*Genus_matched"
844
END$$)::util.derived_col_def);
845
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
846

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

    
853

    
854
--
855
-- Name: COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
856
--
857

    
858
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
859
= CASE
860
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
861
    ELSE "*Specific_epithet_matched"
862
END
863

    
864
derived column
865

    
866
to modify expr:
867
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
868
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
869
    ELSE "*Specific_epithet_matched"
870
END$$)::util.derived_col_def);
871
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
872

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

    
879

    
880
--
881
-- Name: COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
882
--
883

    
884
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
885
= CASE
886
    WHEN matched_has_accepted THEN "*Accepted_name_species"
887
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
888
END
889

    
890
derived column
891

    
892
to modify expr:
893
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
894
    WHEN matched_has_accepted THEN "*Accepted_name_species"
895
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
896
END$$)::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_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
908
--
909

    
910
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
911
= CASE
912
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
913
    ELSE "*Infraspecific_rank"
914
END
915

    
916
derived column
917

    
918
to modify expr:
919
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$CASE
920
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
921
    ELSE "*Infraspecific_rank"
922
END$$)::util.derived_col_def);
923
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
924

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

    
931

    
932
--
933
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
934
--
935

    
936
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
937
= CASE
938
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
939
    ELSE "*Infraspecific_epithet_matched"
940
END
941

    
942
derived column
943

    
944
to modify expr:
945
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
946
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
947
    ELSE "*Infraspecific_epithet_matched"
948
END$$)::util.derived_col_def);
949
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
950

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

    
957

    
958
--
959
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
960
--
961

    
962
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
963
= CASE
964
    WHEN matched_has_accepted THEN "*Accepted_name"
965
    ELSE "*Name_matched"
966
END
967

    
968
derived column
969

    
970
to modify expr:
971
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
972
    WHEN matched_has_accepted THEN "*Accepted_name"
973
    ELSE "*Name_matched"
974
END$$)::util.derived_col_def);
975
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
976

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

    
983

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

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

    
994
derived column
995

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

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

    
1009

    
1010
--
1011
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1012
--
1013

    
1014
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1015
= CASE
1016
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1017
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1018
END
1019

    
1020
derived column
1021

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

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

    
1035

    
1036
--
1037
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1038
--
1039

    
1040
CREATE VIEW taxon_best_match AS
1041
 SELECT taxon_match.batch,
1042
    taxon_match.match_num,
1043
    taxon_match."*Name_number",
1044
    taxon_match."*Name_submitted",
1045
    taxon_match."*Overall_score",
1046
    taxon_match."*Name_matched",
1047
    taxon_match."*Name_matched_rank",
1048
    taxon_match."*Name_score",
1049
    taxon_match."*Name_matched_author",
1050
    taxon_match."*Name_matched_url",
1051
    taxon_match."*Author_matched",
1052
    taxon_match."*Author_score",
1053
    taxon_match."*Family_matched",
1054
    taxon_match."*Family_score",
1055
    taxon_match."*Name_matched_accepted_family",
1056
    taxon_match."*Genus_matched",
1057
    taxon_match."*Genus_score",
1058
    taxon_match."*Specific_epithet_matched",
1059
    taxon_match."*Specific_epithet_score",
1060
    taxon_match."*Infraspecific_rank",
1061
    taxon_match."*Infraspecific_epithet_matched",
1062
    taxon_match."*Infraspecific_epithet_score",
1063
    taxon_match."*Infraspecific_rank_2",
1064
    taxon_match."*Infraspecific_epithet_2_matched",
1065
    taxon_match."*Infraspecific_epithet_2_score",
1066
    taxon_match."*Annotations",
1067
    taxon_match."*Unmatched_terms",
1068
    taxon_match."*Taxonomic_status",
1069
    taxon_match."*Accepted_name",
1070
    taxon_match."*Accepted_name_author",
1071
    taxon_match."*Accepted_name_rank",
1072
    taxon_match."*Accepted_name_url",
1073
    taxon_match."*Accepted_name_species",
1074
    taxon_match."*Accepted_name_family",
1075
    taxon_match."*Selected",
1076
    taxon_match."*Source",
1077
    taxon_match."*Warnings",
1078
    taxon_match."*Accepted_name_lsid",
1079
    taxon_match.is_valid_match,
1080
    taxon_match.scrubbed_unique_taxon_name,
1081
    taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1082
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1083
    taxon_match.matched_has_accepted,
1084
    taxon_match."__accepted_{genus,specific_epithet}",
1085
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
1086
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1087
    taxon_match.__accepted_infraspecific_label,
1088
    taxon_match."__accepted_infraspecific_{rank,epithet}",
1089
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1090
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1091
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1092
    taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1093
    taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1094
    taxon_match."[scrubbed_]genus__@DwC__@vegpath.org",
1095
    taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1096
    taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1097
    taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1098
    taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1099
    taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1100
    taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1101
    taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1102
   FROM taxon_match
1103
  WHERE (taxon_match."*Selected" = 'true'::text);
1104

    
1105

    
1106
--
1107
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1108
--
1109

    
1110
COMMENT ON VIEW taxon_best_match IS '
1111
to modify:
1112
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1113
SELECT __
1114
$$);
1115
';
1116

    
1117

    
1118
--
1119
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1120
--
1121

    
1122
CREATE VIEW "MatchedTaxon" AS
1123
 SELECT taxon_best_match.batch,
1124
    taxon_best_match.match_num,
1125
    taxon_best_match."*Name_number",
1126
    taxon_best_match."*Name_submitted",
1127
    taxon_best_match."*Overall_score",
1128
    taxon_best_match."*Name_matched",
1129
    taxon_best_match."*Name_matched_rank",
1130
    taxon_best_match."*Name_score",
1131
    taxon_best_match."*Name_matched_author",
1132
    taxon_best_match."*Name_matched_url",
1133
    taxon_best_match."*Author_matched",
1134
    taxon_best_match."*Author_score",
1135
    taxon_best_match."*Family_matched",
1136
    taxon_best_match."*Family_score",
1137
    taxon_best_match."*Name_matched_accepted_family",
1138
    taxon_best_match."*Genus_matched",
1139
    taxon_best_match."*Genus_score",
1140
    taxon_best_match."*Specific_epithet_matched",
1141
    taxon_best_match."*Specific_epithet_score",
1142
    taxon_best_match."*Infraspecific_rank",
1143
    taxon_best_match."*Infraspecific_epithet_matched",
1144
    taxon_best_match."*Infraspecific_epithet_score",
1145
    taxon_best_match."*Infraspecific_rank_2",
1146
    taxon_best_match."*Infraspecific_epithet_2_matched",
1147
    taxon_best_match."*Infraspecific_epithet_2_score",
1148
    taxon_best_match."*Annotations",
1149
    taxon_best_match."*Unmatched_terms",
1150
    taxon_best_match."*Taxonomic_status",
1151
    taxon_best_match."*Accepted_name",
1152
    taxon_best_match."*Accepted_name_author",
1153
    taxon_best_match."*Accepted_name_rank",
1154
    taxon_best_match."*Accepted_name_url",
1155
    taxon_best_match."*Accepted_name_species",
1156
    taxon_best_match."*Accepted_name_family",
1157
    taxon_best_match."*Selected",
1158
    taxon_best_match."*Source",
1159
    taxon_best_match."*Warnings",
1160
    taxon_best_match."*Accepted_name_lsid",
1161
    taxon_best_match.is_valid_match,
1162
    taxon_best_match.scrubbed_unique_taxon_name,
1163
    taxon_best_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1164
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1165
    taxon_best_match.matched_has_accepted,
1166
    taxon_best_match."__accepted_{genus,specific_epithet}",
1167
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
1168
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1169
    taxon_best_match.__accepted_infraspecific_label,
1170
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
1171
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1172
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1173
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1174
    taxon_best_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1175
    taxon_best_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1176
    taxon_best_match."[scrubbed_]genus__@DwC__@vegpath.org",
1177
    taxon_best_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1178
    taxon_best_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1179
    taxon_best_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1180
    taxon_best_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1181
    taxon_best_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1182
    taxon_best_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1183
    taxon_best_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1184
    map_taxonomic_status(taxon_best_match."*Taxonomic_status", taxon_best_match."*Accepted_name") AS "taxonomicStatus",
1185
        CASE
1186
            WHEN (taxon_best_match."*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name_family", taxon_best_match."*Unmatched_terms")
1187
            WHEN (taxon_best_match."*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name", taxon_best_match."*Unmatched_terms")
1188
            ELSE taxon_best_match."*Accepted_name_species"
1189
        END AS accepted_morphospecies_binomial
1190
   FROM taxon_best_match;
1191

    
1192

    
1193
--
1194
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1195
--
1196

    
1197
COMMENT ON VIEW "MatchedTaxon" IS '
1198
to modify:
1199
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
1200
SELECT __
1201
$$);
1202
';
1203

    
1204

    
1205
--
1206
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1207
--
1208

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

    
1276

    
1277
--
1278
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1279
--
1280

    
1281
COMMENT ON VIEW "ValidMatchedTaxon" IS '
1282
to update, use * as the column list
1283
';
1284

    
1285

    
1286
--
1287
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1288
--
1289

    
1290
CREATE TABLE batch (
1291
    id text NOT NULL,
1292
    id_by_time text,
1293
    time_submitted timestamp with time zone DEFAULT now(),
1294
    client_version text
1295
);
1296

    
1297

    
1298
--
1299
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1300
--
1301

    
1302
CREATE TABLE batch_download_settings (
1303
    id text NOT NULL,
1304
    "E-mail" text,
1305
    "Id" text,
1306
    "Job type" text,
1307
    "Contains Id" boolean,
1308
    "Start time" text,
1309
    "Finish time" text,
1310
    "TNRS version" text,
1311
    "Sources selected" text,
1312
    "Match threshold" double precision,
1313
    "Classification" text,
1314
    "Allow partial matches?" boolean,
1315
    "Sort by source" boolean,
1316
    "Constrain by higher taxonomy" boolean
1317
);
1318

    
1319

    
1320
--
1321
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
1322
--
1323

    
1324
COMMENT ON TABLE batch_download_settings IS '
1325
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
1326
';
1327

    
1328

    
1329
--
1330
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1331
--
1332

    
1333
CREATE TABLE client_version (
1334
    id text NOT NULL,
1335
    global_rev integer NOT NULL,
1336
    "/lib/tnrs.py rev" integer,
1337
    "/bin/tnrs_db rev" integer
1338
);
1339

    
1340

    
1341
--
1342
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
1343
--
1344

    
1345
COMMENT ON TABLE client_version IS '
1346
contains svn revisions
1347
';
1348

    
1349

    
1350
--
1351
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
1352
--
1353

    
1354
COMMENT ON COLUMN client_version.global_rev IS '
1355
from `svn info .` > Last Changed Rev
1356
';
1357

    
1358

    
1359
--
1360
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
1361
--
1362

    
1363
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
1364
from `svn info lib/tnrs.py` > Last Changed Rev
1365
';
1366

    
1367

    
1368
--
1369
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
1370
--
1371

    
1372
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
1373
from `svn info bin/tnrs_db` > Last Changed Rev
1374
';
1375

    
1376

    
1377
--
1378
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1379
--
1380

    
1381
CREATE VIEW taxon_match_input AS
1382
 SELECT taxon_match."*Name_number" AS "Name_number",
1383
    taxon_match."*Name_submitted" AS "Name_submitted",
1384
    taxon_match."*Overall_score" AS "Overall_score",
1385
    taxon_match."*Name_matched" AS "Name_matched",
1386
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1387
    taxon_match."*Name_score" AS "Name_score",
1388
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1389
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1390
    taxon_match."*Author_matched" AS "Author_matched",
1391
    taxon_match."*Author_score" AS "Author_score",
1392
    taxon_match."*Family_matched" AS "Family_matched",
1393
    taxon_match."*Family_score" AS "Family_score",
1394
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1395
    taxon_match."*Genus_matched" AS "Genus_matched",
1396
    taxon_match."*Genus_score" AS "Genus_score",
1397
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1398
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1399
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1400
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1401
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1402
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1403
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1404
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1405
    taxon_match."*Annotations" AS "Annotations",
1406
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1407
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1408
    taxon_match."*Accepted_name" AS "Accepted_name",
1409
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1410
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1411
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1412
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1413
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1414
    taxon_match."*Selected" AS "Selected",
1415
    taxon_match."*Source" AS "Source",
1416
    taxon_match."*Warnings" AS "Warnings",
1417
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1418
   FROM taxon_match;
1419

    
1420

    
1421
--
1422
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1423
--
1424

    
1425
CREATE TABLE taxon_match_input__copy_to (
1426
    "Name_number" integer,
1427
    "Name_submitted" text,
1428
    "Overall_score" double precision,
1429
    "Name_matched" text,
1430
    "Name_matched_rank" text,
1431
    "Name_score" double precision,
1432
    "Name_matched_author" text,
1433
    "Name_matched_url" text,
1434
    "Author_matched" text,
1435
    "Author_score" double precision,
1436
    "Family_matched" text,
1437
    "Family_score" double precision,
1438
    "Name_matched_accepted_family" text,
1439
    "Genus_matched" text,
1440
    "Genus_score" double precision,
1441
    "Specific_epithet_matched" text,
1442
    "Specific_epithet_score" double precision,
1443
    "Infraspecific_rank" text,
1444
    "Infraspecific_epithet_matched" text,
1445
    "Infraspecific_epithet_score" double precision,
1446
    "Infraspecific_rank_2" text,
1447
    "Infraspecific_epithet_2_matched" text,
1448
    "Infraspecific_epithet_2_score" double precision,
1449
    "Annotations" text,
1450
    "Unmatched_terms" text,
1451
    "Taxonomic_status" text,
1452
    "Accepted_name" text,
1453
    "Accepted_name_author" text,
1454
    "Accepted_name_rank" text,
1455
    "Accepted_name_url" text,
1456
    "Accepted_name_species" text,
1457
    "Accepted_name_family" text,
1458
    "Selected" text,
1459
    "Source" text,
1460
    "Warnings" text,
1461
    "Accepted_name_lsid" text
1462
);
1463

    
1464

    
1465
--
1466
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
1467
--
1468

    
1469
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
1470
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
1471
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
1472
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
1473
    taxon_match."*Genus_matched" AS scrubbed_genus,
1474
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
1475
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
1476
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
1477
    taxon_match."*Name_matched_author" AS scrubbed_author,
1478
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
1479
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
1480
   FROM taxon_match;
1481

    
1482

    
1483
--
1484
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1485
--
1486

    
1487
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1488
to modify:
1489
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1490
SELECT __
1491
$$);
1492

    
1493
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.
1494
';
1495

    
1496

    
1497
--
1498
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1499
--
1500

    
1501
CREATE VIEW taxon_scrub AS
1502
 SELECT "ValidMatchedTaxon".scrubbed_unique_taxon_name,
1503
    "ValidMatchedTaxon".batch,
1504
    "ValidMatchedTaxon".match_num,
1505
    "ValidMatchedTaxon"."*Name_number",
1506
    "ValidMatchedTaxon"."*Name_submitted",
1507
    "ValidMatchedTaxon"."*Overall_score",
1508
    "ValidMatchedTaxon"."*Name_matched",
1509
    "ValidMatchedTaxon"."*Name_matched_rank",
1510
    "ValidMatchedTaxon"."*Name_score",
1511
    "ValidMatchedTaxon"."*Name_matched_author",
1512
    "ValidMatchedTaxon"."*Name_matched_url",
1513
    "ValidMatchedTaxon"."*Author_matched",
1514
    "ValidMatchedTaxon"."*Author_score",
1515
    "ValidMatchedTaxon"."*Family_matched",
1516
    "ValidMatchedTaxon"."*Family_score",
1517
    "ValidMatchedTaxon"."*Name_matched_accepted_family",
1518
    "ValidMatchedTaxon"."*Genus_matched",
1519
    "ValidMatchedTaxon"."*Genus_score",
1520
    "ValidMatchedTaxon"."*Specific_epithet_matched",
1521
    "ValidMatchedTaxon"."*Specific_epithet_score",
1522
    "ValidMatchedTaxon"."*Infraspecific_rank",
1523
    "ValidMatchedTaxon"."*Infraspecific_epithet_matched",
1524
    "ValidMatchedTaxon"."*Infraspecific_epithet_score",
1525
    "ValidMatchedTaxon"."*Infraspecific_rank_2",
1526
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_matched",
1527
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_score",
1528
    "ValidMatchedTaxon"."*Annotations",
1529
    "ValidMatchedTaxon"."*Unmatched_terms",
1530
    "ValidMatchedTaxon"."*Taxonomic_status",
1531
    "ValidMatchedTaxon"."*Accepted_name",
1532
    "ValidMatchedTaxon"."*Accepted_name_author",
1533
    "ValidMatchedTaxon"."*Accepted_name_rank",
1534
    "ValidMatchedTaxon"."*Accepted_name_url",
1535
    "ValidMatchedTaxon"."*Accepted_name_species",
1536
    "ValidMatchedTaxon"."*Accepted_name_family",
1537
    "ValidMatchedTaxon"."*Selected",
1538
    "ValidMatchedTaxon"."*Source",
1539
    "ValidMatchedTaxon"."*Warnings",
1540
    "ValidMatchedTaxon"."*Accepted_name_lsid",
1541
    "ValidMatchedTaxon".is_valid_match,
1542
    "ValidMatchedTaxon"."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1543
    "ValidMatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1544
    "ValidMatchedTaxon".matched_has_accepted,
1545
    "ValidMatchedTaxon"."__accepted_{genus,specific_epithet}",
1546
    "ValidMatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1547
    "ValidMatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1548
    "ValidMatchedTaxon".__accepted_infraspecific_label,
1549
    "ValidMatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1550
    "ValidMatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1551
    "ValidMatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1552
    "ValidMatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1553
    "ValidMatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1554
    "ValidMatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1555
    "ValidMatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org",
1556
    "ValidMatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1557
    "ValidMatchedTaxon"."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1558
    "ValidMatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1559
    "ValidMatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1560
    "ValidMatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1561
    "ValidMatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1562
    "ValidMatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1563
    "ValidMatchedTaxon"."taxonomicStatus",
1564
    "ValidMatchedTaxon".accepted_morphospecies_binomial,
1565
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank,
1566
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family,
1567
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus,
1568
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet,
1569
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_rank,
1570
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_epithet,
1571
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_author,
1572
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author,
1573
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_with_author,
1574
        CASE
1575
            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")
1576
            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")
1577
            ELSE (("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus || ' '::text) || "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet)
1578
        END AS scrubbed_morphospecies_binomial
1579
   FROM ("ValidMatchedTaxon"
1580
   LEFT JOIN "taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name));
1581

    
1582

    
1583
--
1584
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1585
--
1586

    
1587
COMMENT ON VIEW taxon_scrub IS '
1588
to modify:
1589
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1590
SELECT __
1591
$$);
1592
';
1593

    
1594

    
1595
--
1596
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1597
--
1598

    
1599
ALTER TABLE ONLY batch_download_settings
1600
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1601

    
1602

    
1603
--
1604
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1605
--
1606

    
1607
ALTER TABLE ONLY batch
1608
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1609

    
1610

    
1611
--
1612
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1613
--
1614

    
1615
ALTER TABLE ONLY batch
1616
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1617

    
1618

    
1619
--
1620
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1621
--
1622

    
1623
ALTER TABLE ONLY client_version
1624
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1625

    
1626

    
1627
--
1628
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1629
--
1630

    
1631
ALTER TABLE ONLY taxon_match
1632
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1633

    
1634
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1635

    
1636

    
1637
--
1638
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1639
--
1640

    
1641
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1642

    
1643

    
1644
--
1645
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1646
--
1647

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

    
1650

    
1651
--
1652
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1653
--
1654

    
1655
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1656

    
1657

    
1658
--
1659
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1660
--
1661

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

    
1664

    
1665
--
1666
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1667
--
1668

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

    
1671

    
1672
--
1673
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1674
--
1675

    
1676
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1677

    
1678

    
1679
--
1680
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1681
--
1682

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

    
1685

    
1686
--
1687
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1688
--
1689

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

    
1692

    
1693
--
1694
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1695
--
1696

    
1697
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1698

    
1699

    
1700
--
1701
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1702
--
1703

    
1704
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();
1705

    
1706

    
1707
--
1708
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1709
--
1710

    
1711
ALTER TABLE ONLY batch
1712
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1713

    
1714

    
1715
--
1716
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1717
--
1718

    
1719
ALTER TABLE ONLY batch_download_settings
1720
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1721

    
1722

    
1723
--
1724
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1725
--
1726

    
1727
ALTER TABLE ONLY taxon_match
1728
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1729

    
1730

    
1731
--
1732
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1733
--
1734

    
1735
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1736
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1737
GRANT ALL ON SCHEMA "TNRS" TO bien;
1738
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1739

    
1740

    
1741
--
1742
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1743
--
1744

    
1745
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1746
REVOKE ALL ON TABLE taxon_match FROM bien;
1747
GRANT ALL ON TABLE taxon_match TO bien;
1748
GRANT SELECT ON TABLE taxon_match TO bien_read;
1749

    
1750

    
1751
--
1752
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1753
--
1754

    
1755
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1756
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1757
GRANT ALL ON TABLE taxon_best_match TO bien;
1758
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1759

    
1760

    
1761
--
1762
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1763
--
1764

    
1765
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
1766
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
1767
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
1768
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
1769

    
1770

    
1771
--
1772
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1773
--
1774

    
1775
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
1776
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
1777
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
1778
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
1779

    
1780

    
1781
--
1782
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
1783
--
1784

    
1785
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1786
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1787
GRANT ALL ON TABLE taxon_match_input TO bien;
1788
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1789

    
1790

    
1791
--
1792
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
1793
--
1794

    
1795
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
1796
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
1797
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
1798
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
1799

    
1800

    
1801
--
1802
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1803
--
1804

    
1805
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
1806
REVOKE ALL ON TABLE taxon_scrub FROM bien;
1807
GRANT ALL ON TABLE taxon_scrub TO bien;
1808
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
1809

    
1810

    
1811
--
1812
-- PostgreSQL database dump complete
1813
--
1814

    
(7-7/9)