Project

General

Profile

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

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

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

    
16
--CREATE SCHEMA "TNRS";
17

    
18

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

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

    
41

    
42
SET search_path = "TNRS", pg_catalog;
43

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

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

    
58

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

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

    
69

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

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

    
80

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

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

    
94

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

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

    
105

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

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

    
114

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

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

    
128

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

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

    
196

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

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

    
209

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

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

    
322

    
323
--
324
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
325
--
326

    
327
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
328
autogenerated, do not edit
329

    
330
to regenerate:
331
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
332
';
333

    
334

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

    
339
CREATE FUNCTION taxon_match__match_num__fill() RETURNS trigger
340
    LANGUAGE plpgsql
341
    AS $$
342
BEGIN
343
	IF new.match_num IS NULL THEN
344
		new.match_num = "TNRS".taxon_match__match_num__next();
345
	END IF;
346
	RETURN new;
347
END;
348
$$;
349

    
350

    
351
--
352
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
353
--
354

    
355
CREATE FUNCTION taxon_match__match_num__next() RETURNS bigint
356
    LANGUAGE sql
357
    AS $$
358
SELECT nextval('pg_temp.taxon_match__match_num__seq');
359
$$;
360

    
361

    
362
--
363
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
364
--
365

    
366
CREATE FUNCTION taxon_match_input__copy_to__insert() RETURNS trigger
367
    LANGUAGE plpgsql
368
    AS $$
369
BEGIN
370
	INSERT INTO "TNRS".taxon_match_input SELECT new.*;
371
	RETURN NULL;
372
END;
373
$$;
374

    
375

    
376
--
377
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
378
--
379

    
380
CREATE FUNCTION taxon_name_is_safe(taxon_name text) RETURNS boolean
381
    LANGUAGE sql IMMUTABLE
382
    AS $_$
383
SELECT NOT ($1 = ANY("TNRS".unsafe_taxon_names()))
384
$_$;
385

    
386

    
387
--
388
-- Name: unsafe_taxon_names(); Type: FUNCTION; Schema: TNRS; Owner: -
389
--
390

    
391
CREATE FUNCTION unsafe_taxon_names() RETURNS text[]
392
    LANGUAGE sql IMMUTABLE
393
    AS $$
394
SELECT ARRAY[
395
]::text[]
396
$$;
397

    
398

    
399
SET default_tablespace = '';
400

    
401
SET default_with_oids = false;
402

    
403
--
404
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
405
--
406

    
407
CREATE TABLE batch (
408
    id text NOT NULL,
409
    id_by_time text,
410
    time_submitted timestamp with time zone DEFAULT now(),
411
    client_version text
412
);
413

    
414

    
415
--
416
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
417
--
418

    
419
CREATE TABLE batch_download_settings (
420
    id text NOT NULL,
421
    "E-mail" text,
422
    "Id" text,
423
    "Job type" text,
424
    "Contains Id" boolean,
425
    "Start time" text,
426
    "Finish time" text,
427
    "TNRS version" text,
428
    "Sources selected" text,
429
    "Match threshold" double precision,
430
    "Classification" text,
431
    "Allow partial matches?" boolean,
432
    "Sort by source" boolean,
433
    "Constrain by higher taxonomy" boolean
434
);
435

    
436

    
437
--
438
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
439
--
440

    
441
COMMENT ON TABLE batch_download_settings IS '
442
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
443
';
444

    
445

    
446
--
447
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
448
--
449

    
450
CREATE TABLE client_version (
451
    id text NOT NULL,
452
    global_rev integer NOT NULL,
453
    "/lib/tnrs.py rev" integer,
454
    "/bin/tnrs_db rev" integer
455
);
456

    
457

    
458
--
459
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
460
--
461

    
462
COMMENT ON TABLE client_version IS '
463
contains svn revisions
464
';
465

    
466

    
467
--
468
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
469
--
470

    
471
COMMENT ON COLUMN client_version.global_rev IS '
472
from `svn info .` > Last Changed Rev
473
';
474

    
475

    
476
--
477
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
478
--
479

    
480
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
481
from `svn info lib/tnrs.py` > Last Changed Rev
482
';
483

    
484

    
485
--
486
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
487
--
488

    
489
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
490
from `svn info bin/tnrs_db` > Last Changed Rev
491
';
492

    
493

    
494
--
495
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
496
--
497

    
498
CREATE TABLE taxon_match (
499
    batch text DEFAULT now() NOT NULL,
500
    match_num integer NOT NULL,
501
    "*Name_number" integer NOT NULL,
502
    "*Name_submitted" text NOT NULL,
503
    "*Overall_score" double precision,
504
    "*Name_matched" text,
505
    "*Name_matched_rank" text,
506
    "*Name_score" double precision,
507
    "*Name_matched_author" text,
508
    "*Name_matched_url" text,
509
    "*Author_matched" text,
510
    "*Author_score" double precision,
511
    "*Family_matched" text,
512
    "*Family_score" double precision,
513
    "*Name_matched_accepted_family" text,
514
    "*Genus_matched" text,
515
    "*Genus_score" double precision,
516
    "*Specific_epithet_matched" text,
517
    "*Specific_epithet_score" double precision,
518
    "*Infraspecific_rank" text,
519
    "*Infraspecific_epithet_matched" text,
520
    "*Infraspecific_epithet_score" double precision,
521
    "*Infraspecific_rank_2" text,
522
    "*Infraspecific_epithet_2_matched" text,
523
    "*Infraspecific_epithet_2_score" double precision,
524
    "*Annotations" text,
525
    "*Unmatched_terms" text,
526
    "*Taxonomic_status" text,
527
    "*Accepted_name" text,
528
    "*Accepted_name_author" text,
529
    "*Accepted_name_rank" text,
530
    "*Accepted_name_url" text,
531
    "*Accepted_name_species" text,
532
    "*Accepted_name_family" text,
533
    "*Selected" text,
534
    "*Source" text,
535
    "*Warnings" text,
536
    "*Accepted_name_lsid" text,
537
    is_valid_match boolean NOT NULL,
538
    scrubbed_unique_taxon_name text,
539
    "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" text,
540
    "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" text,
541
    "matched~Name[_no_author]___@TNRS__@vegpath.org" text,
542
    "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" text,
543
    matched_has_accepted boolean,
544
    "Accepted_family__@TNRS__@vegpath.org" text,
545
    "Accepted_species[_binomial]__@TNRS__@vegpath.org" text,
546
    "__accepted_{genus,specific_epithet,infra_{rank,epithet}}" text[],
547
    "[accepted_]genus__@DwC__@vegpath.org" text,
548
    "[accepted_]specificEpithet__@DwC__@vegpath.org" text,
549
    "[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" text,
550
    "__accepted_infraspecific_{rank,epithet}" text[],
551
    "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
552
    "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" text,
553
    "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" text,
554
    "[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" text,
555
    "[scrubbed_]taxonRank__@DwC__@vegpath.org" text,
556
    "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" text,
557
    "[scrubbed_]genus__@DwC__@vegpath.org" text,
558
    "[scrubbed_]specificEpithet__@DwC__@vegpath.org" text,
559
    "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" text,
560
    "[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" text,
561
    "[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
562
    "[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" text,
563
    "[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" text,
564
    "[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" text,
565
    "[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" text,
566
    CONSTRAINT "Accepted_family__@TNRS__@vegpath.org" CHECK ((NOT ("Accepted_family__@TNRS__@vegpath.org" IS DISTINCT FROM COALESCE("*Accepted_name_family",
567
CASE
568
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN "*Accepted_name"
569
    ELSE NULL::text
570
END)))),
571
    CONSTRAINT "Accepted_species[_binomial]__@TNRS__@vegpath.org" CHECK ((NOT ("Accepted_species[_binomial]__@TNRS__@vegpath.org" IS DISTINCT FROM rtrim("*Accepted_name_species", ' '::text)))),
572
    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]))),
573
    CONSTRAINT "[accepted_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]genus__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]))),
574
    CONSTRAINT "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_infraspecific_{rank,epithet}"[2]))),
575
    CONSTRAINT "[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" CHECK ((NOT ("[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS DISTINCT FROM
576
CASE
577
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
578
    WHEN ("*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
579
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
580
END))),
581
    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))))),
582
    CONSTRAINT "[accepted_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]))),
583
    CONSTRAINT "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM ("matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE((' '::text || "*Name_matched_author"), ''::text))))),
584
    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")))),
585
    CONSTRAINT "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" CHECK ((NOT ("[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS DISTINCT FROM "*Unmatched_terms"))),
586
    CONSTRAINT "[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS DISTINCT FROM
587
CASE
588
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
589
    ELSE "*Infraspecific_rank"
590
END))),
591
    CONSTRAINT "[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
592
CASE
593
    WHEN matched_has_accepted THEN "*Accepted_name_author"
594
    ELSE "*Name_matched_author"
595
END))),
596
    CONSTRAINT "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
597
CASE
598
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
599
    ELSE "*Name_matched_accepted_family"
600
END))),
601
    CONSTRAINT "[scrubbed_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]genus__@DwC__@vegpath.org" IS DISTINCT FROM
602
CASE
603
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
604
    ELSE "*Genus_matched"
605
END))),
606
    CONSTRAINT "[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM
607
CASE
608
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
609
    ELSE "*Infraspecific_epithet_matched"
610
END))),
611
    CONSTRAINT "[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" CHECK ((NOT ("[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS DISTINCT FROM
612
CASE
613
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'family'::text) THEN concat_ws(' '::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
614
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'genus'::text) THEN concat_ws(' '::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
615
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
616
END))),
617
    CONSTRAINT "[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
618
CASE
619
    WHEN matched_has_accepted THEN "*Accepted_name"
620
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
621
END))),
622
    CONSTRAINT "[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM
623
CASE
624
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
625
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
626
END))),
627
    CONSTRAINT "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
628
CASE
629
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
630
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
631
END))),
632
    CONSTRAINT "[scrubbed_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM
633
CASE
634
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
635
    ELSE "*Specific_epithet_matched"
636
END))),
637
    CONSTRAINT "[scrubbed_]taxonRank__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]taxonRank__@DwC__@vegpath.org" IS DISTINCT FROM
638
CASE
639
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
640
    ELSE "*Name_matched_rank"
641
END))),
642
    CONSTRAINT "[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" IS DISTINCT FROM map_taxonomic_status("*Taxonomic_status", "*Accepted_name")))),
643
    CONSTRAINT "__accepted_infraspecific_{rank,epithet}" CHECK ((NOT ("__accepted_infraspecific_{rank,epithet}" IS DISTINCT FROM NULLIF("__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[3:4], '{}'::text[])))),
644
    CONSTRAINT "__accepted_{genus,specific_epithet,infra_{rank,epithet}}" CHECK ((NOT ("__accepted_{genus,specific_epithet,infra_{rank,epithet}}" IS DISTINCT FROM regexp_split_to_array("*Accepted_name", ' '::text)))),
645
    CONSTRAINT matched_has_accepted CHECK ((NOT (matched_has_accepted IS DISTINCT FROM ("*Accepted_name" IS NOT NULL)))),
646
    CONSTRAINT "matched~Name[_no_author]___@TNRS__@vegpath.org" CHECK ((NOT ("matched~Name[_no_author]___@TNRS__@vegpath.org" IS DISTINCT FROM NULLIF("*Name_matched", 'No suitable matches found.'::text))))
647
);
648

    
649

    
650
--
651
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
652
--
653

    
654
COMMENT ON TABLE taxon_match IS '
655
whenever columns are renamed:
656
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
657

    
658
to port derived column changes to vegbiendev:
659
SELECT util.derived_cols_export(''"TNRS".taxon_match'');
660
# run the returned SQL on vegbiendev
661
	-- runtime: 6 h, 2.6 ms/row ("22030570 ms"; "rows=8353235")
662
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
663

    
664
to add a new derived column:
665
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''col''), $$
666
expr
667
$$));
668
SELECT util.derived_cols_populate(''"TNRS".taxon_match'');
669
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
670
$ make schemas/remake
671

    
672
to remove a derived column:
673
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''col''));
674
$ make schemas/remake
675

    
676
to remove a non-derived column:
677
SELECT util.drop_column((''"TNRS".taxon_match'', ''col''));
678
$ make schemas/remake
679

    
680
to move a derived column to the middle or to add a non-derived column:
681
make the changes in inputs/.TNRS/schema.sql
682
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS; runtime: 1 min ("1m2.629s")
683
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
684
SELECT util.derived_cols_repopulate(''"TNRS".taxon_match'');
685
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
686
$ make schemas/remake
687

    
688
to add a constraint: runtime: 3 min ("173620 ms")
689
';
690

    
691

    
692
--
693
-- Name: COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
694
--
695

    
696
COMMENT ON COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS '
697
= "*Unmatched_terms"
698

    
699
derived column
700

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

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

    
710
to drop:
711
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org'')::util.col);
712
	-- DROP __ CASCADE doesn''t work when there are dependent views
713
';
714

    
715

    
716
--
717
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
718
--
719

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

    
723
derived column
724

    
725
to modify expr:
726
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);
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
to drop:
735
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
736
	-- DROP __ CASCADE doesn''t work when there are dependent views
737
';
738

    
739

    
740
--
741
-- Name: COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
742
--
743

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

    
747
derived column
748

    
749
to modify expr:
750
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched~Name[_no_author]___@TNRS__@vegpath.org'')::util.col, $$NULLIF("*Name_matched", ''No suitable matches found.''::text)$$)::util.derived_col_def);
751
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
752

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

    
758
to drop:
759
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''matched~Name[_no_author]___@TNRS__@vegpath.org'')::util.col);
760
	-- DROP __ CASCADE doesn''t work when there are dependent views
761
';
762

    
763

    
764
--
765
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
766
--
767

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

    
771
derived column
772

    
773
to modify expr:
774
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)$$)::util.derived_col_def);
775
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
776

    
777
to rename:
778
# rename column
779
# rename CHECK constraint
780
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
781

    
782
to drop:
783
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
784
	-- DROP __ CASCADE doesn''t work when there are dependent views
785
';
786

    
787

    
788
--
789
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
790
--
791

    
792
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
793
= "*Accepted_name" IS NOT NULL
794

    
795
derived column
796

    
797
to modify expr:
798
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
799
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
800

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

    
806
to drop:
807
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col);
808
	-- DROP __ CASCADE doesn''t work when there are dependent views
809
';
810

    
811

    
812
--
813
-- Name: COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
814
--
815

    
816
COMMENT ON COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org" IS '
817
= COALESCE("*Accepted_name_family",
818
CASE
819
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
820
    ELSE NULL::text
821
END)
822

    
823
derived column
824

    
825
to modify expr:
826
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col, $$COALESCE("*Accepted_name_family",
827
CASE
828
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
829
    ELSE NULL::text
830
END)$$)::util.derived_col_def);
831
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
832

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

    
838
to drop:
839
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col);
840
	-- DROP __ CASCADE doesn''t work when there are dependent views
841
';
842

    
843

    
844
--
845
-- Name: COLUMN taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
846
--
847

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

    
851
derived column
852

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

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

    
862
to drop:
863
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''Accepted_species[_binomial]__@TNRS__@vegpath.org'')::util.col);
864
	-- DROP __ CASCADE doesn''t work when there are dependent views
865
';
866

    
867

    
868
--
869
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}"; Type: COMMENT; Schema: TNRS; Owner: -
870
--
871

    
872
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" IS '
873
= regexp_split_to_array("*Accepted_name", '' ''::text)
874

    
875
derived column
876

    
877
to modify expr:
878
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet,infra_{rank,epithet}}'')::util.col, $$regexp_split_to_array("*Accepted_name", '' ''::text)$$)::util.derived_col_def);
879
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
880

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

    
886
to drop:
887
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet,infra_{rank,epithet}}'')::util.col);
888
	-- DROP __ CASCADE doesn''t work when there are dependent views
889
';
890

    
891

    
892
--
893
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
894
--
895

    
896
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
897
= "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]
898

    
899
derived column
900

    
901
to modify expr:
902
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]$$)::util.derived_col_def);
903
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
904

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

    
910
to drop:
911
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col);
912
	-- DROP __ CASCADE doesn''t work when there are dependent views
913
';
914

    
915

    
916
--
917
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
918
--
919

    
920
COMMENT ON COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org" IS '
921
= "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]
922

    
923
derived column
924

    
925
to modify expr:
926
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]$$)::util.derived_col_def);
927
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
928

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

    
934
to drop:
935
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col);
936
	-- DROP __ CASCADE doesn''t work when there are dependent views
937
';
938

    
939

    
940
--
941
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
942
--
943

    
944
COMMENT ON COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
945
= CASE
946
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
947
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
948
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
949
END
950

    
951
derived column
952

    
953
to modify expr:
954
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
955
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
956
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
957
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
958
END$$)::util.derived_col_def);
959
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
960

    
961
to rename:
962
# rename column
963
# rename CHECK constraint
964
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
965

    
966
to drop:
967
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col);
968
	-- DROP __ CASCADE doesn''t work when there are dependent views
969
';
970

    
971

    
972
--
973
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
974
--
975

    
976
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
977
= NULLIF("__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[3:4], ''{}''::text[])
978

    
979
derived column
980

    
981
to modify expr:
982
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col, $$NULLIF("__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[3:4], ''{}''::text[])$$)::util.derived_col_def);
983
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
984

    
985
to rename:
986
# rename column
987
# rename CHECK constraint
988
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
989

    
990
to drop:
991
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col);
992
	-- DROP __ CASCADE doesn''t work when there are dependent views
993
';
994

    
995

    
996
--
997
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
998
--
999

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

    
1003
derived column
1004

    
1005
to modify expr:
1006
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);
1007
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1008

    
1009
to rename:
1010
# rename column
1011
# rename CHECK constraint
1012
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1013

    
1014
to drop:
1015
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col);
1016
	-- DROP __ CASCADE doesn''t work when there are dependent views
1017
';
1018

    
1019

    
1020
--
1021
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1022
--
1023

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

    
1027
derived column
1028

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

    
1033
to rename:
1034
# rename column
1035
# rename CHECK constraint
1036
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1037

    
1038
to drop:
1039
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col);
1040
	-- DROP __ CASCADE doesn''t work when there are dependent views
1041
';
1042

    
1043

    
1044
--
1045
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1046
--
1047

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

    
1051
derived column
1052

    
1053
to modify expr:
1054
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);
1055
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1056

    
1057
to rename:
1058
# rename column
1059
# rename CHECK constraint
1060
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1061

    
1062
to drop:
1063
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
1064
	-- DROP __ CASCADE doesn''t work when there are dependent views
1065
';
1066

    
1067

    
1068
--
1069
-- Name: COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1070
--
1071

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

    
1075
derived column
1076

    
1077
to modify expr:
1078
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonomicStatus__@DwC__@vegpath.org'')::util.col, $$"TNRS".map_taxonomic_status("*Taxonomic_status", "*Accepted_name")$$)::util.derived_col_def);
1079
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1080

    
1081
to rename:
1082
# rename column
1083
# rename CHECK constraint
1084
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1085

    
1086
to drop:
1087
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]taxonomicStatus__@DwC__@vegpath.org'')::util.col);
1088
	-- DROP __ CASCADE doesn''t work when there are dependent views
1089
';
1090

    
1091

    
1092
--
1093
-- Name: COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1094
--
1095

    
1096
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
1097
= CASE
1098
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
1099
    ELSE "*Name_matched_rank"
1100
END
1101

    
1102
derived column
1103

    
1104
to modify expr:
1105
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
1106
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
1107
    ELSE "*Name_matched_rank"
1108
END$$)::util.derived_col_def);
1109
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1110

    
1111
to rename:
1112
# rename column
1113
# rename CHECK constraint
1114
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1115

    
1116
to drop:
1117
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col);
1118
	-- DROP __ CASCADE doesn''t work when there are dependent views
1119
';
1120

    
1121

    
1122
--
1123
-- Name: COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1124
--
1125

    
1126
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1127
= CASE
1128
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
1129
    ELSE "*Name_matched_accepted_family"
1130
END
1131

    
1132
derived column
1133

    
1134
to modify expr:
1135
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1136
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
1137
    ELSE "*Name_matched_accepted_family"
1138
END$$)::util.derived_col_def);
1139
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1140

    
1141
to rename:
1142
# rename column
1143
# rename CHECK constraint
1144
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1145

    
1146
to drop:
1147
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1148
	-- DROP __ CASCADE doesn''t work when there are dependent views
1149
';
1150

    
1151

    
1152
--
1153
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1154
--
1155

    
1156
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
1157
= CASE
1158
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1159
    ELSE "*Genus_matched"
1160
END
1161

    
1162
derived column
1163

    
1164
to modify expr:
1165
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
1166
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1167
    ELSE "*Genus_matched"
1168
END$$)::util.derived_col_def);
1169
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1170

    
1171
to rename:
1172
# rename column
1173
# rename CHECK constraint
1174
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1175

    
1176
to drop:
1177
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col);
1178
	-- DROP __ CASCADE doesn''t work when there are dependent views
1179
';
1180

    
1181

    
1182
--
1183
-- Name: COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1184
--
1185

    
1186
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
1187
= CASE
1188
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1189
    ELSE "*Specific_epithet_matched"
1190
END
1191

    
1192
derived column
1193

    
1194
to modify expr:
1195
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1196
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1197
    ELSE "*Specific_epithet_matched"
1198
END$$)::util.derived_col_def);
1199
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1200

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

    
1206
to drop:
1207
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col);
1208
	-- DROP __ CASCADE doesn''t work when there are dependent views
1209
';
1210

    
1211

    
1212
--
1213
-- Name: COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1214
--
1215

    
1216
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1217
= CASE
1218
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1219
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1220
END
1221

    
1222
derived column
1223

    
1224
to modify expr:
1225
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1226
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1227
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1228
END$$)::util.derived_col_def);
1229
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1230

    
1231
to rename:
1232
# rename column
1233
# rename CHECK constraint
1234
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1235

    
1236
to drop:
1237
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1238
	-- DROP __ CASCADE doesn''t work when there are dependent views
1239
';
1240

    
1241

    
1242
--
1243
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1244
--
1245

    
1246
COMMENT ON COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
1247
= CASE
1248
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''family''::text) THEN concat_ws('' ''::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1249
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1250
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1251
END
1252

    
1253
derived column
1254

    
1255
to modify expr:
1256
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
1257
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''family''::text) THEN concat_ws('' ''::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1258
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1259
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1260
END$$)::util.derived_col_def);
1261
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1262

    
1263
to rename:
1264
# rename column
1265
# rename CHECK constraint
1266
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1267

    
1268
to drop:
1269
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col);
1270
	-- DROP __ CASCADE doesn''t work when there are dependent views
1271
';
1272

    
1273

    
1274
--
1275
-- Name: COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1276
--
1277

    
1278
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1279
= CASE
1280
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1281
    ELSE "*Infraspecific_rank"
1282
END
1283

    
1284
derived column
1285

    
1286
to modify expr:
1287
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$CASE
1288
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1289
    ELSE "*Infraspecific_rank"
1290
END$$)::util.derived_col_def);
1291
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1292

    
1293
to rename:
1294
# rename column
1295
# rename CHECK constraint
1296
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1297

    
1298
to drop:
1299
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col);
1300
	-- DROP __ CASCADE doesn''t work when there are dependent views
1301
';
1302

    
1303

    
1304
--
1305
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1306
--
1307

    
1308
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1309
= CASE
1310
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1311
    ELSE "*Infraspecific_epithet_matched"
1312
END
1313

    
1314
derived column
1315

    
1316
to modify expr:
1317
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1318
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1319
    ELSE "*Infraspecific_epithet_matched"
1320
END$$)::util.derived_col_def);
1321
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1322

    
1323
to rename:
1324
# rename column
1325
# rename CHECK constraint
1326
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1327

    
1328
to drop:
1329
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col);
1330
	-- DROP __ CASCADE doesn''t work when there are dependent views
1331
';
1332

    
1333

    
1334
--
1335
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1336
--
1337

    
1338
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1339
= CASE
1340
    WHEN matched_has_accepted THEN "*Accepted_name"
1341
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1342
END
1343

    
1344
derived column
1345

    
1346
to modify expr:
1347
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1348
    WHEN matched_has_accepted THEN "*Accepted_name"
1349
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1350
END$$)::util.derived_col_def);
1351
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1352

    
1353
to rename:
1354
# rename column
1355
# rename CHECK constraint
1356
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1357

    
1358
to drop:
1359
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1360
	-- DROP __ CASCADE doesn''t work when there are dependent views
1361
';
1362

    
1363

    
1364
--
1365
-- Name: COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1366
--
1367

    
1368
COMMENT ON COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1369
= CASE
1370
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1371
    ELSE "*Name_matched_author"
1372
END
1373

    
1374
derived column
1375

    
1376
to modify expr:
1377
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1378
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1379
    ELSE "*Name_matched_author"
1380
END$$)::util.derived_col_def);
1381
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1382

    
1383
to rename:
1384
# rename column
1385
# rename CHECK constraint
1386
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1387

    
1388
to drop:
1389
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1390
	-- DROP __ CASCADE doesn''t work when there are dependent views
1391
';
1392

    
1393

    
1394
--
1395
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1396
--
1397

    
1398
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1399
= CASE
1400
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1401
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1402
END
1403

    
1404
derived column
1405

    
1406
to modify expr:
1407
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$CASE
1408
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1409
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1410
END$$)::util.derived_col_def);
1411
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1412

    
1413
to rename:
1414
# rename column
1415
# rename CHECK constraint
1416
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1417

    
1418
to drop:
1419
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
1420
	-- DROP __ CASCADE doesn''t work when there are dependent views
1421
';
1422

    
1423

    
1424
--
1425
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1426
--
1427

    
1428
CREATE VIEW taxon_best_match AS
1429
 SELECT taxon_match.batch,
1430
    taxon_match.match_num,
1431
    taxon_match."*Name_number",
1432
    taxon_match."*Name_submitted",
1433
    taxon_match."*Overall_score",
1434
    taxon_match."*Name_matched",
1435
    taxon_match."*Name_matched_rank",
1436
    taxon_match."*Name_score",
1437
    taxon_match."*Name_matched_author",
1438
    taxon_match."*Name_matched_url",
1439
    taxon_match."*Author_matched",
1440
    taxon_match."*Author_score",
1441
    taxon_match."*Family_matched",
1442
    taxon_match."*Family_score",
1443
    taxon_match."*Name_matched_accepted_family",
1444
    taxon_match."*Genus_matched",
1445
    taxon_match."*Genus_score",
1446
    taxon_match."*Specific_epithet_matched",
1447
    taxon_match."*Specific_epithet_score",
1448
    taxon_match."*Infraspecific_rank",
1449
    taxon_match."*Infraspecific_epithet_matched",
1450
    taxon_match."*Infraspecific_epithet_score",
1451
    taxon_match."*Infraspecific_rank_2",
1452
    taxon_match."*Infraspecific_epithet_2_matched",
1453
    taxon_match."*Infraspecific_epithet_2_score",
1454
    taxon_match."*Annotations",
1455
    taxon_match."*Unmatched_terms",
1456
    taxon_match."*Taxonomic_status",
1457
    taxon_match."*Accepted_name",
1458
    taxon_match."*Accepted_name_author",
1459
    taxon_match."*Accepted_name_rank",
1460
    taxon_match."*Accepted_name_url",
1461
    taxon_match."*Accepted_name_species",
1462
    taxon_match."*Accepted_name_family",
1463
    taxon_match."*Selected",
1464
    taxon_match."*Source",
1465
    taxon_match."*Warnings",
1466
    taxon_match."*Accepted_name_lsid",
1467
    taxon_match.is_valid_match,
1468
    taxon_match.scrubbed_unique_taxon_name,
1469
    taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1470
    taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1471
    taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org",
1472
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1473
    taxon_match.matched_has_accepted,
1474
    taxon_match."Accepted_family__@TNRS__@vegpath.org",
1475
    taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1476
    taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}",
1477
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
1478
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1479
    taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1480
    taxon_match."__accepted_infraspecific_{rank,epithet}",
1481
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1482
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1483
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1484
    taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1485
    taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1486
    taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1487
    taxon_match."[scrubbed_]genus__@DwC__@vegpath.org",
1488
    taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1489
    taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1490
    taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1491
    taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1492
    taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1493
    taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1494
    taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1495
    taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1496
   FROM taxon_match
1497
  WHERE (taxon_match."*Selected" = 'true'::text);
1498

    
1499

    
1500
--
1501
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1502
--
1503

    
1504
COMMENT ON VIEW taxon_best_match IS '
1505
to modify:
1506
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1507
SELECT __
1508
$$);
1509
';
1510

    
1511

    
1512
--
1513
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1514
--
1515

    
1516
CREATE VIEW taxon_match_input AS
1517
 SELECT taxon_match."*Name_number" AS "Name_number",
1518
    taxon_match."*Name_submitted" AS "Name_submitted",
1519
    taxon_match."*Overall_score" AS "Overall_score",
1520
    taxon_match."*Name_matched" AS "Name_matched",
1521
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1522
    taxon_match."*Name_score" AS "Name_score",
1523
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1524
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1525
    taxon_match."*Author_matched" AS "Author_matched",
1526
    taxon_match."*Author_score" AS "Author_score",
1527
    taxon_match."*Family_matched" AS "Family_matched",
1528
    taxon_match."*Family_score" AS "Family_score",
1529
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1530
    taxon_match."*Genus_matched" AS "Genus_matched",
1531
    taxon_match."*Genus_score" AS "Genus_score",
1532
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1533
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1534
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1535
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1536
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1537
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1538
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1539
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1540
    taxon_match."*Annotations" AS "Annotations",
1541
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1542
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1543
    taxon_match."*Accepted_name" AS "Accepted_name",
1544
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1545
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1546
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1547
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1548
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1549
    taxon_match."*Selected" AS "Selected",
1550
    taxon_match."*Source" AS "Source",
1551
    taxon_match."*Warnings" AS "Warnings",
1552
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1553
   FROM taxon_match;
1554

    
1555

    
1556
--
1557
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1558
--
1559

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

    
1599

    
1600
--
1601
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1602
--
1603

    
1604
CREATE VIEW taxon_scrub AS
1605
 SELECT taxon_best_match.batch,
1606
    taxon_best_match.match_num,
1607
    taxon_best_match."*Name_number",
1608
    taxon_best_match."*Name_submitted",
1609
    taxon_best_match."*Overall_score",
1610
    taxon_best_match."*Name_matched",
1611
    taxon_best_match."*Name_matched_rank",
1612
    taxon_best_match."*Name_score",
1613
    taxon_best_match."*Name_matched_author",
1614
    taxon_best_match."*Name_matched_url",
1615
    taxon_best_match."*Author_matched",
1616
    taxon_best_match."*Author_score",
1617
    taxon_best_match."*Family_matched",
1618
    taxon_best_match."*Family_score",
1619
    taxon_best_match."*Name_matched_accepted_family",
1620
    taxon_best_match."*Genus_matched",
1621
    taxon_best_match."*Genus_score",
1622
    taxon_best_match."*Specific_epithet_matched",
1623
    taxon_best_match."*Specific_epithet_score",
1624
    taxon_best_match."*Infraspecific_rank",
1625
    taxon_best_match."*Infraspecific_epithet_matched",
1626
    taxon_best_match."*Infraspecific_epithet_score",
1627
    taxon_best_match."*Infraspecific_rank_2",
1628
    taxon_best_match."*Infraspecific_epithet_2_matched",
1629
    taxon_best_match."*Infraspecific_epithet_2_score",
1630
    taxon_best_match."*Annotations",
1631
    taxon_best_match."*Unmatched_terms",
1632
    taxon_best_match."*Taxonomic_status",
1633
    taxon_best_match."*Accepted_name",
1634
    taxon_best_match."*Accepted_name_author",
1635
    taxon_best_match."*Accepted_name_rank",
1636
    taxon_best_match."*Accepted_name_url",
1637
    taxon_best_match."*Accepted_name_species",
1638
    taxon_best_match."*Accepted_name_family",
1639
    taxon_best_match."*Selected",
1640
    taxon_best_match."*Source",
1641
    taxon_best_match."*Warnings",
1642
    taxon_best_match."*Accepted_name_lsid",
1643
    taxon_best_match.is_valid_match,
1644
    taxon_best_match.scrubbed_unique_taxon_name,
1645
    taxon_best_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1646
    taxon_best_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1647
    taxon_best_match."matched~Name[_no_author]___@TNRS__@vegpath.org",
1648
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1649
    taxon_best_match.matched_has_accepted,
1650
    taxon_best_match."Accepted_family__@TNRS__@vegpath.org",
1651
    taxon_best_match."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1652
    taxon_best_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}",
1653
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
1654
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1655
    taxon_best_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1656
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
1657
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1658
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1659
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1660
    taxon_best_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1661
    taxon_best_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1662
    taxon_best_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1663
    taxon_best_match."[scrubbed_]genus__@DwC__@vegpath.org",
1664
    taxon_best_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1665
    taxon_best_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1666
    taxon_best_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1667
    taxon_best_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1668
    taxon_best_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1669
    taxon_best_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1670
    taxon_best_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1671
    taxon_best_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1672
   FROM taxon_best_match
1673
  WHERE taxon_best_match.is_valid_match;
1674

    
1675

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

    
1680
COMMENT ON VIEW taxon_scrub IS '
1681
to modify:
1682
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1683
SELECT __
1684
$$);
1685

    
1686
to merge synonymous columns:
1687
# temporarily move correct col out of the way, to allow renaming synonym col:
1688
ALTER TABLE "TNRS".taxon_scrub RENAME "correct_col" TO "_correct_col";
1689
## also perform the rename in any dependent .* views (currently there are none)
1690
# rename columns to replace:
1691
ALTER TABLE "TNRS".taxon_scrub RENAME "synonym_col" TO "correct_col";
1692
## also perform the rename in any dependent .* views (currently there are none)
1693
# remove duplicate cols and now-unnecessary CASE wrappers
1694
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1695
SELECT __ -- with the CASE-wrapped synonym col removed
1696
$$);
1697
';
1698

    
1699

    
1700
--
1701
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1702
--
1703

    
1704
ALTER TABLE ONLY batch_download_settings
1705
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1706

    
1707

    
1708
--
1709
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1710
--
1711

    
1712
ALTER TABLE ONLY batch
1713
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1714

    
1715

    
1716
--
1717
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1718
--
1719

    
1720
ALTER TABLE ONLY batch
1721
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1722

    
1723

    
1724
--
1725
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1726
--
1727

    
1728
ALTER TABLE ONLY client_version
1729
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1730

    
1731

    
1732
--
1733
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1734
--
1735

    
1736
ALTER TABLE ONLY taxon_match
1737
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1738

    
1739
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1740

    
1741

    
1742
--
1743
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1744
--
1745

    
1746
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1747

    
1748

    
1749
--
1750
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1751
--
1752

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

    
1755

    
1756
--
1757
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1758
--
1759

    
1760
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1761

    
1762

    
1763
--
1764
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1765
--
1766

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

    
1769

    
1770
--
1771
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1772
--
1773

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

    
1776

    
1777
--
1778
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1779
--
1780

    
1781
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1782

    
1783

    
1784
--
1785
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1786
--
1787

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

    
1790

    
1791
--
1792
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1793
--
1794

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

    
1797

    
1798
--
1799
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1800
--
1801

    
1802
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1803

    
1804

    
1805
--
1806
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1807
--
1808

    
1809
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();
1810

    
1811

    
1812
--
1813
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1814
--
1815

    
1816
ALTER TABLE ONLY batch
1817
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1818

    
1819

    
1820
--
1821
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1822
--
1823

    
1824
ALTER TABLE ONLY batch_download_settings
1825
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1826

    
1827

    
1828
--
1829
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1830
--
1831

    
1832
ALTER TABLE ONLY taxon_match
1833
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1834

    
1835

    
1836
--
1837
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1838
--
1839

    
1840
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1841
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1842
GRANT ALL ON SCHEMA "TNRS" TO bien;
1843
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1844

    
1845

    
1846
--
1847
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1848
--
1849

    
1850
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1851
REVOKE ALL ON TABLE taxon_match FROM bien;
1852
GRANT ALL ON TABLE taxon_match TO bien;
1853
GRANT SELECT ON TABLE taxon_match TO bien_read;
1854

    
1855

    
1856
--
1857
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1858
--
1859

    
1860
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1861
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1862
GRANT ALL ON TABLE taxon_best_match TO bien;
1863
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1864

    
1865

    
1866
--
1867
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
1868
--
1869

    
1870
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1871
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1872
GRANT ALL ON TABLE taxon_match_input TO bien;
1873
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1874

    
1875

    
1876
--
1877
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1878
--
1879

    
1880
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
1881
REVOKE ALL ON TABLE taxon_scrub FROM bien;
1882
GRANT ALL ON TABLE taxon_scrub TO bien;
1883
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
1884

    
1885

    
1886
--
1887
-- PostgreSQL database dump complete
1888
--
1889

    
(7-7/9)