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."__accepted_{genus,specific_epithet}" = (SELECT
199
		regexp_split_to_array("*Accepted_name_species", ' '::text)
200
		FROM (SELECT new.*) new);
201
	
202
	new."[accepted_]genus__@DwC__@vegpath.org" = (SELECT
203
		"__accepted_{genus,specific_epithet}"[1]
204
		FROM (SELECT new.*) new);
205
	
206
	new."[accepted_]specificEpithet__@DwC__@vegpath.org" = (SELECT
207
		"__accepted_{genus,specific_epithet}"[2]
208
		FROM (SELECT new.*) new);
209
	
210
	new.__accepted_infraspecific_label = (SELECT
211
		ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''::text), ' '::text)
212
		FROM (SELECT new.*) new);
213
	
214
	new."__accepted_infraspecific_{rank,epithet}" = (SELECT
215
		regexp_split_to_array(__accepted_infraspecific_label, ' '::text)
216
		FROM (SELECT new.*) new);
217
	
218
	new."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = (SELECT
219
		"__accepted_infraspecific_{rank,epithet}"[1]
220
		FROM (SELECT new.*) new);
221
	
222
	new."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" = (SELECT
223
		"__accepted_infraspecific_{rank,epithet}"[2]
224
		FROM (SELECT new.*) new);
225
	
226
	new."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT
227
		"*Name_matched" || COALESCE((' '::text || "*Name_matched_author"), ''::text)
228
		FROM (SELECT new.*) new);
229
	
230
	new."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT
231
		"*Accepted_name" || COALESCE((' '::text || "*Accepted_name_author"), ''::text)
232
		FROM (SELECT new.*) new);
233
	
234
	new.matched_has_accepted = (SELECT
235
		"*Accepted_name" IS NOT NULL
236
		FROM (SELECT new.*) new);
237
	
238
	RETURN new;
239
END;
240
$$;
241

    
242

    
243
--
244
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
245
--
246

    
247
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
248
autogenerated, do not edit
249

    
250
to regenerate:
251
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
252
';
253

    
254

    
255
--
256
-- Name: taxon_match__match_num__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
257
--
258

    
259
CREATE FUNCTION taxon_match__match_num__fill() RETURNS trigger
260
    LANGUAGE plpgsql
261
    AS $$
262
BEGIN
263
	IF new.match_num IS NULL THEN
264
		new.match_num = "TNRS".taxon_match__match_num__next();
265
	END IF;
266
	RETURN new;
267
END;
268
$$;
269

    
270

    
271
--
272
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
273
--
274

    
275
CREATE FUNCTION taxon_match__match_num__next() RETURNS bigint
276
    LANGUAGE sql
277
    AS $$
278
SELECT nextval('pg_temp.taxon_match__match_num__seq');
279
$$;
280

    
281

    
282
--
283
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
284
--
285

    
286
CREATE FUNCTION taxon_match_input__copy_to__insert() RETURNS trigger
287
    LANGUAGE plpgsql
288
    AS $$
289
BEGIN
290
	INSERT INTO "TNRS".taxon_match_input SELECT new.*;
291
	RETURN NULL;
292
END;
293
$$;
294

    
295

    
296
--
297
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
298
--
299

    
300
CREATE FUNCTION taxon_name_is_safe(taxon_name text) RETURNS boolean
301
    LANGUAGE sql IMMUTABLE
302
    AS $_$
303
SELECT NOT ($1 = ANY("TNRS".unsafe_taxon_names()))
304
$_$;
305

    
306

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

    
311
CREATE FUNCTION unsafe_taxon_names() RETURNS text[]
312
    LANGUAGE sql IMMUTABLE
313
    AS $$
314
SELECT ARRAY[
315
]::text[]
316
$$;
317

    
318

    
319
SET default_tablespace = '';
320

    
321
SET default_with_oids = false;
322

    
323
--
324
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
325
--
326

    
327
CREATE TABLE taxon_match (
328
    batch text DEFAULT now() NOT NULL,
329
    match_num integer NOT NULL,
330
    "*Name_number" integer NOT NULL,
331
    "*Name_submitted" text NOT NULL,
332
    "*Overall_score" double precision,
333
    "*Name_matched" text,
334
    "*Name_matched_rank" text,
335
    "*Name_score" double precision,
336
    "*Name_matched_author" text,
337
    "*Name_matched_url" text,
338
    "*Author_matched" text,
339
    "*Author_score" double precision,
340
    "*Family_matched" text,
341
    "*Family_score" double precision,
342
    "*Name_matched_accepted_family" text,
343
    "*Genus_matched" text,
344
    "*Genus_score" double precision,
345
    "*Specific_epithet_matched" text,
346
    "*Specific_epithet_score" double precision,
347
    "*Infraspecific_rank" text,
348
    "*Infraspecific_epithet_matched" text,
349
    "*Infraspecific_epithet_score" double precision,
350
    "*Infraspecific_rank_2" text,
351
    "*Infraspecific_epithet_2_matched" text,
352
    "*Infraspecific_epithet_2_score" double precision,
353
    "*Annotations" text,
354
    "*Unmatched_terms" text,
355
    "*Taxonomic_status" text,
356
    "*Accepted_name" text,
357
    "*Accepted_name_author" text,
358
    "*Accepted_name_rank" text,
359
    "*Accepted_name_url" text,
360
    "*Accepted_name_species" text,
361
    "*Accepted_name_family" text,
362
    "*Selected" text,
363
    "*Source" text,
364
    "*Warnings" text,
365
    "*Accepted_name_lsid" text,
366
    is_valid_match boolean NOT NULL,
367
    scrubbed_unique_taxon_name text,
368
    "__accepted_{genus,specific_epithet}" text[],
369
    "[accepted_]genus__@DwC__@vegpath.org" text,
370
    "[accepted_]specificEpithet__@DwC__@vegpath.org" text,
371
    __accepted_infraspecific_label text,
372
    "__accepted_infraspecific_{rank,epithet}" text[],
373
    "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
374
    "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" text,
375
    "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" text,
376
    "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" text,
377
    matched_has_accepted boolean,
378
    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]))),
379
    CONSTRAINT "[accepted_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]genus__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet}"[1]))),
380
    CONSTRAINT "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_infraspecific_{rank,epithet}"[2]))),
381
    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))))),
382
    CONSTRAINT "[accepted_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet}"[2]))),
383
    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))))),
384
    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)))),
385
    CONSTRAINT "__accepted_infraspecific_{rank,epithet}" CHECK ((NOT ("__accepted_infraspecific_{rank,epithet}" IS DISTINCT FROM regexp_split_to_array(__accepted_infraspecific_label, ' '::text)))),
386
    CONSTRAINT "__accepted_{genus,specific_epithet}" CHECK ((NOT ("__accepted_{genus,specific_epithet}" IS DISTINCT FROM regexp_split_to_array("*Accepted_name_species", ' '::text)))),
387
    CONSTRAINT matched_has_accepted CHECK ((NOT (matched_has_accepted IS DISTINCT FROM ("*Accepted_name" IS NOT NULL))))
388
);
389

    
390

    
391
--
392
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
393
--
394

    
395
COMMENT ON TABLE taxon_match IS '
396
whenever columns are renamed:
397
SELECT util.derived_cols_sync(''"TNRS".taxon_match'');
398

    
399
to remove columns or add columns at the end:
400
$ rm=1 inputs/.TNRS/data.sql.run
401
$ make schemas/remake
402

    
403
to add columns in the middle:
404
make the changes in inputs/.TNRS/schema.sql
405
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS
406
$ make schemas/remake
407

    
408
to populate a new column:
409
ALTER TABLE "TNRS".taxon_match DISABLE TRIGGER taxon_match__fill; --speeds up update
410
UPDATE "TNRS".taxon_match SET "col" = value;
411
	-- runtime: 30 min ("5564201 rows affected, 1624829 ms execution time")
412
CLUSTER "TNRS".taxon_match; -- ensure rows are exported in sorted order
413
ALTER TABLE "TNRS".taxon_match ENABLE TRIGGER taxon_match__fill;
414
VACUUM ANALYZE "TNRS".taxon_match --remove previous rows; runtime: 1.5 min ("92633 ms")
415

    
416
to add a constraint: runtime: 3 min ("173620 ms")
417
';
418

    
419

    
420
--
421
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
422
--
423

    
424
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet}" IS '
425
derived column; = regexp_split_to_array("*Accepted_name_species", '' ''::text)
426

    
427
to modify expr:
428
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);
429
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
430

    
431
to rename:
432
# rename column
433
# rename CHECK constraint
434
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
435
';
436

    
437

    
438
--
439
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
440
--
441

    
442
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
443
derived column; = "__accepted_{genus,specific_epithet}"[1]
444

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

    
449
to rename:
450
# rename column
451
# rename CHECK constraint
452
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
453
';
454

    
455

    
456
--
457
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
458
--
459

    
460
COMMENT ON COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org" IS '
461
derived column; = "__accepted_{genus,specific_epithet}"[2]
462

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

    
467
to rename:
468
# rename column
469
# rename CHECK constraint
470
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
471
';
472

    
473

    
474
--
475
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
476
--
477

    
478
COMMENT ON COLUMN taxon_match.__accepted_infraspecific_label IS '
479
derived column; = ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''''::text), '' ''::text)
480

    
481
to modify expr:
482
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);
483
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
484

    
485
to rename:
486
# rename column
487
# rename CHECK constraint
488
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
489
';
490

    
491

    
492
--
493
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
494
--
495

    
496
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
497
derived column; = regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
498

    
499
to modify expr:
500
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);
501
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
502

    
503
to rename:
504
# rename column
505
# rename CHECK constraint
506
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
507
';
508

    
509

    
510
--
511
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
512
--
513

    
514
COMMENT ON COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
515
derived column; = "__accepted_infraspecific_{rank,epithet}"[1]
516

    
517
to modify expr:
518
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);
519
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
520

    
521
to rename:
522
# rename column
523
# rename CHECK constraint
524
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
525
';
526

    
527

    
528
--
529
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
530
--
531

    
532
COMMENT ON COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS '
533
derived column; = "__accepted_infraspecific_{rank,epithet}"[2]
534

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

    
539
to rename:
540
# rename column
541
# rename CHECK constraint
542
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
543
';
544

    
545

    
546
--
547
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
548
--
549

    
550
COMMENT ON COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
551
derived column; = "*Name_matched" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)
552

    
553
to modify expr:
554
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);
555
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
556

    
557
to rename:
558
# rename column
559
# rename CHECK constraint
560
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
561
';
562

    
563

    
564
--
565
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
566
--
567

    
568
COMMENT ON COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
569
derived column; = "*Accepted_name" || COALESCE(('' ''::text || "*Accepted_name_author"), ''''::text)
570

    
571
to modify expr:
572
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);
573
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
574

    
575
to rename:
576
# rename column
577
# rename CHECK constraint
578
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
579
';
580

    
581

    
582
--
583
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
584
--
585

    
586
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
587
derived column; = "*Accepted_name" IS NOT NULL
588

    
589
to modify expr:
590
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
591
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
592

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

    
599

    
600
--
601
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
602
--
603

    
604
CREATE VIEW taxon_best_match AS
605
 SELECT taxon_match.batch,
606
    taxon_match.match_num,
607
    taxon_match."*Name_number",
608
    taxon_match."*Name_submitted",
609
    taxon_match."*Overall_score",
610
    taxon_match."*Name_matched",
611
    taxon_match."*Name_matched_rank",
612
    taxon_match."*Name_score",
613
    taxon_match."*Name_matched_author",
614
    taxon_match."*Name_matched_url",
615
    taxon_match."*Author_matched",
616
    taxon_match."*Author_score",
617
    taxon_match."*Family_matched",
618
    taxon_match."*Family_score",
619
    taxon_match."*Name_matched_accepted_family",
620
    taxon_match."*Genus_matched",
621
    taxon_match."*Genus_score",
622
    taxon_match."*Specific_epithet_matched",
623
    taxon_match."*Specific_epithet_score",
624
    taxon_match."*Infraspecific_rank",
625
    taxon_match."*Infraspecific_epithet_matched",
626
    taxon_match."*Infraspecific_epithet_score",
627
    taxon_match."*Infraspecific_rank_2",
628
    taxon_match."*Infraspecific_epithet_2_matched",
629
    taxon_match."*Infraspecific_epithet_2_score",
630
    taxon_match."*Annotations",
631
    taxon_match."*Unmatched_terms",
632
    taxon_match."*Taxonomic_status",
633
    taxon_match."*Accepted_name",
634
    taxon_match."*Accepted_name_author",
635
    taxon_match."*Accepted_name_rank",
636
    taxon_match."*Accepted_name_url",
637
    taxon_match."*Accepted_name_species",
638
    taxon_match."*Accepted_name_family",
639
    taxon_match."*Selected",
640
    taxon_match."*Source",
641
    taxon_match."*Warnings",
642
    taxon_match."*Accepted_name_lsid",
643
    taxon_match.is_valid_match,
644
    taxon_match.scrubbed_unique_taxon_name,
645
    taxon_match."__accepted_{genus,specific_epithet}",
646
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
647
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
648
    taxon_match.__accepted_infraspecific_label,
649
    taxon_match."__accepted_infraspecific_{rank,epithet}",
650
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
651
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
652
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
653
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
654
   FROM taxon_match
655
  WHERE (taxon_match."*Selected" = 'true'::text);
656

    
657

    
658
--
659
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
660
--
661

    
662
COMMENT ON VIEW taxon_best_match IS '
663
to modify:
664
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
665
SELECT __
666
$$);
667
';
668

    
669

    
670
--
671
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
672
--
673

    
674
CREATE VIEW "MatchedTaxon" AS
675
 SELECT taxon_best_match.batch,
676
    taxon_best_match.match_num,
677
    taxon_best_match."*Name_number",
678
    taxon_best_match."*Name_submitted",
679
    taxon_best_match."*Overall_score",
680
    taxon_best_match."*Name_matched",
681
    taxon_best_match."*Name_matched_rank",
682
    taxon_best_match."*Name_score",
683
    taxon_best_match."*Name_matched_author",
684
    taxon_best_match."*Name_matched_url",
685
    taxon_best_match."*Author_matched",
686
    taxon_best_match."*Author_score",
687
    taxon_best_match."*Family_matched",
688
    taxon_best_match."*Family_score",
689
    taxon_best_match."*Name_matched_accepted_family",
690
    taxon_best_match."*Genus_matched",
691
    taxon_best_match."*Genus_score",
692
    taxon_best_match."*Specific_epithet_matched",
693
    taxon_best_match."*Specific_epithet_score",
694
    taxon_best_match."*Infraspecific_rank",
695
    taxon_best_match."*Infraspecific_epithet_matched",
696
    taxon_best_match."*Infraspecific_epithet_score",
697
    taxon_best_match."*Infraspecific_rank_2",
698
    taxon_best_match."*Infraspecific_epithet_2_matched",
699
    taxon_best_match."*Infraspecific_epithet_2_score",
700
    taxon_best_match."*Annotations",
701
    taxon_best_match."*Unmatched_terms",
702
    taxon_best_match."*Taxonomic_status",
703
    taxon_best_match."*Accepted_name",
704
    taxon_best_match."*Accepted_name_author",
705
    taxon_best_match."*Accepted_name_rank",
706
    taxon_best_match."*Accepted_name_url",
707
    taxon_best_match."*Accepted_name_species",
708
    taxon_best_match."*Accepted_name_family",
709
    taxon_best_match."*Selected",
710
    taxon_best_match."*Source",
711
    taxon_best_match."*Warnings",
712
    taxon_best_match."*Accepted_name_lsid",
713
    taxon_best_match.is_valid_match,
714
    taxon_best_match.scrubbed_unique_taxon_name,
715
    taxon_best_match."__accepted_{genus,specific_epithet}",
716
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
717
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
718
    taxon_best_match.__accepted_infraspecific_label,
719
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
720
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
721
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
722
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
723
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
724
    map_taxonomic_status(taxon_best_match."*Taxonomic_status", taxon_best_match."*Accepted_name") AS "taxonomicStatus",
725
        CASE
726
            WHEN (taxon_best_match."*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name_family", taxon_best_match."*Unmatched_terms")
727
            WHEN (taxon_best_match."*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name", taxon_best_match."*Unmatched_terms")
728
            ELSE taxon_best_match."*Accepted_name_species"
729
        END AS accepted_morphospecies_binomial
730
   FROM taxon_best_match;
731

    
732

    
733
--
734
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
735
--
736

    
737
COMMENT ON VIEW "MatchedTaxon" IS '
738
to modify:
739
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
740
SELECT __
741
$$);
742
';
743

    
744

    
745
--
746
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
747
--
748

    
749
CREATE VIEW "ValidMatchedTaxon" AS
750
 SELECT "MatchedTaxon".batch,
751
    "MatchedTaxon".match_num,
752
    "MatchedTaxon"."*Name_number",
753
    "MatchedTaxon"."*Name_submitted",
754
    "MatchedTaxon"."*Overall_score",
755
    "MatchedTaxon"."*Name_matched",
756
    "MatchedTaxon"."*Name_matched_rank",
757
    "MatchedTaxon"."*Name_score",
758
    "MatchedTaxon"."*Name_matched_author",
759
    "MatchedTaxon"."*Name_matched_url",
760
    "MatchedTaxon"."*Author_matched",
761
    "MatchedTaxon"."*Author_score",
762
    "MatchedTaxon"."*Family_matched",
763
    "MatchedTaxon"."*Family_score",
764
    "MatchedTaxon"."*Name_matched_accepted_family",
765
    "MatchedTaxon"."*Genus_matched",
766
    "MatchedTaxon"."*Genus_score",
767
    "MatchedTaxon"."*Specific_epithet_matched",
768
    "MatchedTaxon"."*Specific_epithet_score",
769
    "MatchedTaxon"."*Infraspecific_rank",
770
    "MatchedTaxon"."*Infraspecific_epithet_matched",
771
    "MatchedTaxon"."*Infraspecific_epithet_score",
772
    "MatchedTaxon"."*Infraspecific_rank_2",
773
    "MatchedTaxon"."*Infraspecific_epithet_2_matched",
774
    "MatchedTaxon"."*Infraspecific_epithet_2_score",
775
    "MatchedTaxon"."*Annotations",
776
    "MatchedTaxon"."*Unmatched_terms",
777
    "MatchedTaxon"."*Taxonomic_status",
778
    "MatchedTaxon"."*Accepted_name",
779
    "MatchedTaxon"."*Accepted_name_author",
780
    "MatchedTaxon"."*Accepted_name_rank",
781
    "MatchedTaxon"."*Accepted_name_url",
782
    "MatchedTaxon"."*Accepted_name_species",
783
    "MatchedTaxon"."*Accepted_name_family",
784
    "MatchedTaxon"."*Selected",
785
    "MatchedTaxon"."*Source",
786
    "MatchedTaxon"."*Warnings",
787
    "MatchedTaxon"."*Accepted_name_lsid",
788
    "MatchedTaxon".is_valid_match,
789
    "MatchedTaxon".scrubbed_unique_taxon_name,
790
    "MatchedTaxon"."__accepted_{genus,specific_epithet}",
791
    "MatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
792
    "MatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
793
    "MatchedTaxon".__accepted_infraspecific_label,
794
    "MatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
795
    "MatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
796
    "MatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
797
    "MatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
798
    "MatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
799
    "MatchedTaxon"."taxonomicStatus",
800
    "MatchedTaxon".accepted_morphospecies_binomial
801
   FROM "MatchedTaxon"
802
  WHERE "MatchedTaxon".is_valid_match;
803

    
804

    
805
--
806
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
807
--
808

    
809
COMMENT ON VIEW "ValidMatchedTaxon" IS '
810
to update, use * as the column list
811
';
812

    
813

    
814
--
815
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
816
--
817

    
818
CREATE TABLE batch (
819
    id text NOT NULL,
820
    id_by_time text,
821
    time_submitted timestamp with time zone DEFAULT now(),
822
    client_version text
823
);
824

    
825

    
826
--
827
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
828
--
829

    
830
CREATE TABLE batch_download_settings (
831
    id text NOT NULL,
832
    "E-mail" text,
833
    "Id" text,
834
    "Job type" text,
835
    "Contains Id" boolean,
836
    "Start time" text,
837
    "Finish time" text,
838
    "TNRS version" text,
839
    "Sources selected" text,
840
    "Match threshold" double precision,
841
    "Classification" text,
842
    "Allow partial matches?" boolean,
843
    "Sort by source" boolean,
844
    "Constrain by higher taxonomy" boolean
845
);
846

    
847

    
848
--
849
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
850
--
851

    
852
COMMENT ON TABLE batch_download_settings IS '
853
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
854
';
855

    
856

    
857
--
858
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
859
--
860

    
861
CREATE TABLE client_version (
862
    id text NOT NULL,
863
    global_rev integer NOT NULL,
864
    "/lib/tnrs.py rev" integer,
865
    "/bin/tnrs_db rev" integer
866
);
867

    
868

    
869
--
870
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
871
--
872

    
873
COMMENT ON TABLE client_version IS '
874
contains svn revisions
875
';
876

    
877

    
878
--
879
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
880
--
881

    
882
COMMENT ON COLUMN client_version.global_rev IS '
883
from `svn info .` > Last Changed Rev
884
';
885

    
886

    
887
--
888
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
889
--
890

    
891
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
892
from `svn info lib/tnrs.py` > Last Changed Rev
893
';
894

    
895

    
896
--
897
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
898
--
899

    
900
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
901
from `svn info bin/tnrs_db` > Last Changed Rev
902
';
903

    
904

    
905
--
906
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
907
--
908

    
909
CREATE VIEW taxon_match_input AS
910
 SELECT taxon_match."*Name_number" AS "Name_number",
911
    taxon_match."*Name_submitted" AS "Name_submitted",
912
    taxon_match."*Overall_score" AS "Overall_score",
913
    taxon_match."*Name_matched" AS "Name_matched",
914
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
915
    taxon_match."*Name_score" AS "Name_score",
916
    taxon_match."*Name_matched_author" AS "Name_matched_author",
917
    taxon_match."*Name_matched_url" AS "Name_matched_url",
918
    taxon_match."*Author_matched" AS "Author_matched",
919
    taxon_match."*Author_score" AS "Author_score",
920
    taxon_match."*Family_matched" AS "Family_matched",
921
    taxon_match."*Family_score" AS "Family_score",
922
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
923
    taxon_match."*Genus_matched" AS "Genus_matched",
924
    taxon_match."*Genus_score" AS "Genus_score",
925
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
926
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
927
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
928
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
929
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
930
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
931
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
932
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
933
    taxon_match."*Annotations" AS "Annotations",
934
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
935
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
936
    taxon_match."*Accepted_name" AS "Accepted_name",
937
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
938
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
939
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
940
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
941
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
942
    taxon_match."*Selected" AS "Selected",
943
    taxon_match."*Source" AS "Source",
944
    taxon_match."*Warnings" AS "Warnings",
945
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
946
   FROM taxon_match;
947

    
948

    
949
--
950
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
951
--
952

    
953
CREATE TABLE taxon_match_input__copy_to (
954
    "Name_number" integer,
955
    "Name_submitted" text,
956
    "Overall_score" double precision,
957
    "Name_matched" text,
958
    "Name_matched_rank" text,
959
    "Name_score" double precision,
960
    "Name_matched_author" text,
961
    "Name_matched_url" text,
962
    "Author_matched" text,
963
    "Author_score" double precision,
964
    "Family_matched" text,
965
    "Family_score" double precision,
966
    "Name_matched_accepted_family" text,
967
    "Genus_matched" text,
968
    "Genus_score" double precision,
969
    "Specific_epithet_matched" text,
970
    "Specific_epithet_score" double precision,
971
    "Infraspecific_rank" text,
972
    "Infraspecific_epithet_matched" text,
973
    "Infraspecific_epithet_score" double precision,
974
    "Infraspecific_rank_2" text,
975
    "Infraspecific_epithet_2_matched" text,
976
    "Infraspecific_epithet_2_score" double precision,
977
    "Annotations" text,
978
    "Unmatched_terms" text,
979
    "Taxonomic_status" text,
980
    "Accepted_name" text,
981
    "Accepted_name_author" text,
982
    "Accepted_name_rank" text,
983
    "Accepted_name_url" text,
984
    "Accepted_name_species" text,
985
    "Accepted_name_family" text,
986
    "Selected" text,
987
    "Source" text,
988
    "Warnings" text,
989
    "Accepted_name_lsid" text
990
);
991

    
992

    
993
--
994
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
995
--
996

    
997
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
998
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
999
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
1000
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
1001
    taxon_match."*Genus_matched" AS scrubbed_genus,
1002
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
1003
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
1004
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
1005
    taxon_match."*Name_matched_author" AS scrubbed_author,
1006
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
1007
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
1008
   FROM taxon_match;
1009

    
1010

    
1011
--
1012
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1013
--
1014

    
1015
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1016
to modify:
1017
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1018
SELECT __
1019
$$);
1020

    
1021
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.
1022
';
1023

    
1024

    
1025
--
1026
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1027
--
1028

    
1029
CREATE VIEW taxon_scrub AS
1030
 SELECT "ValidMatchedTaxon".scrubbed_unique_taxon_name,
1031
    "ValidMatchedTaxon".batch,
1032
    "ValidMatchedTaxon".match_num,
1033
    "ValidMatchedTaxon"."*Name_number",
1034
    "ValidMatchedTaxon"."*Name_submitted",
1035
    "ValidMatchedTaxon"."*Overall_score",
1036
    "ValidMatchedTaxon"."*Name_matched",
1037
    "ValidMatchedTaxon"."*Name_matched_rank",
1038
    "ValidMatchedTaxon"."*Name_score",
1039
    "ValidMatchedTaxon"."*Name_matched_author",
1040
    "ValidMatchedTaxon"."*Name_matched_url",
1041
    "ValidMatchedTaxon"."*Author_matched",
1042
    "ValidMatchedTaxon"."*Author_score",
1043
    "ValidMatchedTaxon"."*Family_matched",
1044
    "ValidMatchedTaxon"."*Family_score",
1045
    "ValidMatchedTaxon"."*Name_matched_accepted_family",
1046
    "ValidMatchedTaxon"."*Genus_matched",
1047
    "ValidMatchedTaxon"."*Genus_score",
1048
    "ValidMatchedTaxon"."*Specific_epithet_matched",
1049
    "ValidMatchedTaxon"."*Specific_epithet_score",
1050
    "ValidMatchedTaxon"."*Infraspecific_rank",
1051
    "ValidMatchedTaxon"."*Infraspecific_epithet_matched",
1052
    "ValidMatchedTaxon"."*Infraspecific_epithet_score",
1053
    "ValidMatchedTaxon"."*Infraspecific_rank_2",
1054
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_matched",
1055
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_score",
1056
    "ValidMatchedTaxon"."*Annotations",
1057
    "ValidMatchedTaxon"."*Unmatched_terms",
1058
    "ValidMatchedTaxon"."*Taxonomic_status",
1059
    "ValidMatchedTaxon"."*Accepted_name",
1060
    "ValidMatchedTaxon"."*Accepted_name_author",
1061
    "ValidMatchedTaxon"."*Accepted_name_rank",
1062
    "ValidMatchedTaxon"."*Accepted_name_url",
1063
    "ValidMatchedTaxon"."*Accepted_name_species",
1064
    "ValidMatchedTaxon"."*Accepted_name_family",
1065
    "ValidMatchedTaxon"."*Selected",
1066
    "ValidMatchedTaxon"."*Source",
1067
    "ValidMatchedTaxon"."*Warnings",
1068
    "ValidMatchedTaxon"."*Accepted_name_lsid",
1069
    "ValidMatchedTaxon".is_valid_match,
1070
    "ValidMatchedTaxon"."__accepted_{genus,specific_epithet}",
1071
    "ValidMatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1072
    "ValidMatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1073
    "ValidMatchedTaxon".__accepted_infraspecific_label,
1074
    "ValidMatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1075
    "ValidMatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1076
    "ValidMatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1077
    "ValidMatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1078
    "ValidMatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1079
    "ValidMatchedTaxon"."taxonomicStatus",
1080
    "ValidMatchedTaxon".accepted_morphospecies_binomial,
1081
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank,
1082
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family,
1083
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus,
1084
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet,
1085
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_rank,
1086
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_epithet,
1087
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_author,
1088
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author,
1089
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_with_author,
1090
        CASE
1091
            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")
1092
            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")
1093
            ELSE (("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus || ' '::text) || "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet)
1094
        END AS scrubbed_morphospecies_binomial
1095
   FROM ("ValidMatchedTaxon"
1096
   LEFT JOIN "taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name));
1097

    
1098

    
1099
--
1100
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1101
--
1102

    
1103
COMMENT ON VIEW taxon_scrub IS '
1104
to modify:
1105
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1106
SELECT __
1107
$$);
1108
';
1109

    
1110

    
1111
--
1112
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1113
--
1114

    
1115
ALTER TABLE ONLY batch_download_settings
1116
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1117

    
1118

    
1119
--
1120
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1121
--
1122

    
1123
ALTER TABLE ONLY batch
1124
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1125

    
1126

    
1127
--
1128
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1129
--
1130

    
1131
ALTER TABLE ONLY batch
1132
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1133

    
1134

    
1135
--
1136
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1137
--
1138

    
1139
ALTER TABLE ONLY client_version
1140
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1141

    
1142

    
1143
--
1144
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1145
--
1146

    
1147
ALTER TABLE ONLY taxon_match
1148
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1149

    
1150
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1151

    
1152

    
1153
--
1154
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1155
--
1156

    
1157
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1158

    
1159

    
1160
--
1161
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1162
--
1163

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

    
1166

    
1167
--
1168
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1169
--
1170

    
1171
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1172

    
1173

    
1174
--
1175
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1176
--
1177

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

    
1180

    
1181
--
1182
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1183
--
1184

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

    
1187

    
1188
--
1189
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1190
--
1191

    
1192
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1193

    
1194

    
1195
--
1196
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1197
--
1198

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

    
1201

    
1202
--
1203
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1204
--
1205

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

    
1208

    
1209
--
1210
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1211
--
1212

    
1213
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1214

    
1215

    
1216
--
1217
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1218
--
1219

    
1220
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();
1221

    
1222

    
1223
--
1224
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1225
--
1226

    
1227
ALTER TABLE ONLY batch
1228
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1229

    
1230

    
1231
--
1232
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1233
--
1234

    
1235
ALTER TABLE ONLY batch_download_settings
1236
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1237

    
1238

    
1239
--
1240
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1241
--
1242

    
1243
ALTER TABLE ONLY taxon_match
1244
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1245

    
1246

    
1247
--
1248
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1249
--
1250

    
1251
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1252
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1253
GRANT ALL ON SCHEMA "TNRS" TO bien;
1254
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1255

    
1256

    
1257
--
1258
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1259
--
1260

    
1261
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1262
REVOKE ALL ON TABLE taxon_match FROM bien;
1263
GRANT ALL ON TABLE taxon_match TO bien;
1264
GRANT SELECT ON TABLE taxon_match TO bien_read;
1265

    
1266

    
1267
--
1268
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1269
--
1270

    
1271
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1272
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1273
GRANT ALL ON TABLE taxon_best_match TO bien;
1274
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1275

    
1276

    
1277
--
1278
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1279
--
1280

    
1281
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
1282
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
1283
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
1284
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
1285

    
1286

    
1287
--
1288
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1289
--
1290

    
1291
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
1292
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
1293
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
1294
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
1295

    
1296

    
1297
--
1298
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
1299
--
1300

    
1301
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1302
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1303
GRANT ALL ON TABLE taxon_match_input TO bien;
1304
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1305

    
1306

    
1307
--
1308
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
1309
--
1310

    
1311
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
1312
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
1313
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
1314
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
1315

    
1316

    
1317
--
1318
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1319
--
1320

    
1321
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
1322
REVOKE ALL ON TABLE taxon_scrub FROM bien;
1323
GRANT ALL ON TABLE taxon_scrub TO bien;
1324
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
1325

    
1326

    
1327
--
1328
-- PostgreSQL database dump complete
1329
--
1330

    
(7-7/9)