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: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
405
--
406

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

    
558

    
559
--
560
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
561
--
562

    
563
COMMENT ON TABLE taxon_match IS '
564
whenever columns are renamed:
565
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
566

    
567
to port derived column changes to vegbiendev:
568
SELECT util.derived_cols_export(''"TNRS".taxon_match'');
569
# run the returned SQL on vegbiendev
570
	-- runtime: 6 h, 2.6 ms/row ("22030570 ms"; "rows=8353235")
571
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
572

    
573
to add a new derived column:
574
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''col''), $$
575
expr
576
$$));
577
SELECT util.derived_cols_populate(''"TNRS".taxon_match'');
578
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
579
$ make schemas/remake
580

    
581
to remove a derived column:
582
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''col''));
583
$ make schemas/remake
584

    
585
to remove a non-derived column:
586
SELECT util.drop_column((''"TNRS".taxon_match'', ''col''));
587
$ make schemas/remake
588

    
589
to move a derived column to the middle or to add a non-derived column:
590
make the changes in inputs/.TNRS/schema.sql
591
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS; runtime: 1 min ("1m2.629s")
592
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
593
SELECT util.derived_cols_repopulate(''"TNRS".taxon_match'');
594
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
595
$ make schemas/remake
596

    
597
to add a constraint: runtime: 3 min ("173620 ms")
598
';
599

    
600

    
601
--
602
-- Name: COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
603
--
604

    
605
COMMENT ON COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS '
606
= "*Unmatched_terms"
607

    
608
derived column
609

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

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

    
619
to drop:
620
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org'')::util.col);
621
	-- DROP __ CASCADE doesn''t work when there are dependent views
622
';
623

    
624

    
625
--
626
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
627
--
628

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

    
632
derived column
633

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

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

    
643
to drop:
644
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
645
	-- DROP __ CASCADE doesn''t work when there are dependent views
646
';
647

    
648

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

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

    
656
derived column
657

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

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

    
667
to drop:
668
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''matched~Name[_no_author]___@TNRS__@vegpath.org'')::util.col);
669
	-- DROP __ CASCADE doesn''t work when there are dependent views
670
';
671

    
672

    
673
--
674
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
675
--
676

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

    
680
derived column
681

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

    
686
to rename:
687
# rename column
688
# rename CHECK constraint
689
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
690

    
691
to drop:
692
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
693
	-- DROP __ CASCADE doesn''t work when there are dependent views
694
';
695

    
696

    
697
--
698
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
699
--
700

    
701
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
702
= "*Accepted_name" IS NOT NULL
703

    
704
derived column
705

    
706
to modify expr:
707
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
708
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
709

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

    
715
to drop:
716
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col);
717
	-- DROP __ CASCADE doesn''t work when there are dependent views
718
';
719

    
720

    
721
--
722
-- Name: COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
723
--
724

    
725
COMMENT ON COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org" IS '
726
= COALESCE("*Accepted_name_family",
727
CASE
728
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
729
    ELSE NULL::text
730
END)
731

    
732
derived column
733

    
734
to modify expr:
735
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col, $$COALESCE("*Accepted_name_family",
736
CASE
737
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
738
    ELSE NULL::text
739
END)$$)::util.derived_col_def);
740
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
741

    
742
to rename:
743
# rename column
744
# rename CHECK constraint
745
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
746

    
747
to drop:
748
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col);
749
	-- DROP __ CASCADE doesn''t work when there are dependent views
750
';
751

    
752

    
753
--
754
-- Name: COLUMN taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
755
--
756

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

    
760
derived column
761

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

    
766
to rename:
767
# rename column
768
# rename CHECK constraint
769
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
770

    
771
to drop:
772
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''Accepted_species[_binomial]__@TNRS__@vegpath.org'')::util.col);
773
	-- DROP __ CASCADE doesn''t work when there are dependent views
774
';
775

    
776

    
777
--
778
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}"; Type: COMMENT; Schema: TNRS; Owner: -
779
--
780

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

    
784
derived column
785

    
786
to modify expr:
787
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);
788
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
789

    
790
to rename:
791
# rename column
792
# rename CHECK constraint
793
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
794

    
795
to drop:
796
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet,infra_{rank,epithet}}'')::util.col);
797
	-- DROP __ CASCADE doesn''t work when there are dependent views
798
';
799

    
800

    
801
--
802
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
803
--
804

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

    
808
derived column
809

    
810
to modify expr:
811
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);
812
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
813

    
814
to rename:
815
# rename column
816
# rename CHECK constraint
817
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
818

    
819
to drop:
820
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col);
821
	-- DROP __ CASCADE doesn''t work when there are dependent views
822
';
823

    
824

    
825
--
826
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
827
--
828

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

    
832
derived column
833

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

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

    
843
to drop:
844
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col);
845
	-- DROP __ CASCADE doesn''t work when there are dependent views
846
';
847

    
848

    
849
--
850
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
851
--
852

    
853
COMMENT ON COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
854
= CASE
855
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
856
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
857
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
858
END
859

    
860
derived column
861

    
862
to modify expr:
863
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
864
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
865
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
866
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
867
END$$)::util.derived_col_def);
868
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
869

    
870
to rename:
871
# rename column
872
# rename CHECK constraint
873
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
874

    
875
to drop:
876
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col);
877
	-- DROP __ CASCADE doesn''t work when there are dependent views
878
';
879

    
880

    
881
--
882
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
883
--
884

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

    
888
derived column
889

    
890
to modify expr:
891
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);
892
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
893

    
894
to rename:
895
# rename column
896
# rename CHECK constraint
897
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
898

    
899
to drop:
900
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col);
901
	-- DROP __ CASCADE doesn''t work when there are dependent views
902
';
903

    
904

    
905
--
906
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
907
--
908

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

    
912
derived column
913

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

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

    
923
to drop:
924
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col);
925
	-- DROP __ CASCADE doesn''t work when there are dependent views
926
';
927

    
928

    
929
--
930
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
931
--
932

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

    
936
derived column
937

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

    
942
to rename:
943
# rename column
944
# rename CHECK constraint
945
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
946

    
947
to drop:
948
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col);
949
	-- DROP __ CASCADE doesn''t work when there are dependent views
950
';
951

    
952

    
953
--
954
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
955
--
956

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

    
960
derived column
961

    
962
to modify expr:
963
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);
964
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
965

    
966
to rename:
967
# rename column
968
# rename CHECK constraint
969
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
970

    
971
to drop:
972
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
973
	-- DROP __ CASCADE doesn''t work when there are dependent views
974
';
975

    
976

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

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

    
984
derived column
985

    
986
to modify expr:
987
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);
988
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
989

    
990
to rename:
991
# rename column
992
# rename CHECK constraint
993
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
994

    
995
to drop:
996
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]taxonomicStatus__@DwC__@vegpath.org'')::util.col);
997
	-- DROP __ CASCADE doesn''t work when there are dependent views
998
';
999

    
1000

    
1001
--
1002
-- Name: COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1003
--
1004

    
1005
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
1006
= CASE
1007
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
1008
    ELSE "*Name_matched_rank"
1009
END
1010

    
1011
derived column
1012

    
1013
to modify expr:
1014
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
1015
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
1016
    ELSE "*Name_matched_rank"
1017
END$$)::util.derived_col_def);
1018
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1019

    
1020
to rename:
1021
# rename column
1022
# rename CHECK constraint
1023
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1024

    
1025
to drop:
1026
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col);
1027
	-- DROP __ CASCADE doesn''t work when there are dependent views
1028
';
1029

    
1030

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

    
1035
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1036
= CASE
1037
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
1038
    ELSE "*Name_matched_accepted_family"
1039
END
1040

    
1041
derived column
1042

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

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

    
1055
to drop:
1056
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1057
	-- DROP __ CASCADE doesn''t work when there are dependent views
1058
';
1059

    
1060

    
1061
--
1062
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1063
--
1064

    
1065
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
1066
= CASE
1067
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1068
    ELSE "*Genus_matched"
1069
END
1070

    
1071
derived column
1072

    
1073
to modify expr:
1074
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
1075
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1076
    ELSE "*Genus_matched"
1077
END$$)::util.derived_col_def);
1078
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1079

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

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

    
1090

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

    
1095
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
1096
= CASE
1097
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1098
    ELSE "*Specific_epithet_matched"
1099
END
1100

    
1101
derived column
1102

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

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

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

    
1120

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

    
1125
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1126
= CASE
1127
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1128
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1129
END
1130

    
1131
derived column
1132

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

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

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

    
1150

    
1151
--
1152
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1153
--
1154

    
1155
COMMENT ON COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
1156
= CASE
1157
    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")
1158
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1159
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1160
END
1161

    
1162
derived column
1163

    
1164
to modify expr:
1165
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
1166
    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")
1167
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1168
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1169
END$$)::util.derived_col_def);
1170
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1171

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

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

    
1182

    
1183
--
1184
-- Name: COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1185
--
1186

    
1187
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1188
= CASE
1189
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1190
    ELSE "*Infraspecific_rank"
1191
END
1192

    
1193
derived column
1194

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

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

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

    
1212

    
1213
--
1214
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1215
--
1216

    
1217
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1218
= CASE
1219
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1220
    ELSE "*Infraspecific_epithet_matched"
1221
END
1222

    
1223
derived column
1224

    
1225
to modify expr:
1226
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1227
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1228
    ELSE "*Infraspecific_epithet_matched"
1229
END$$)::util.derived_col_def);
1230
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1231

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

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

    
1242

    
1243
--
1244
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1245
--
1246

    
1247
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1248
= CASE
1249
    WHEN matched_has_accepted THEN "*Accepted_name"
1250
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1251
END
1252

    
1253
derived column
1254

    
1255
to modify expr:
1256
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1257
    WHEN matched_has_accepted THEN "*Accepted_name"
1258
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1259
END$$)::util.derived_col_def);
1260
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1261

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

    
1267
to drop:
1268
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1269
	-- DROP __ CASCADE doesn''t work when there are dependent views
1270
';
1271

    
1272

    
1273
--
1274
-- Name: COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1275
--
1276

    
1277
COMMENT ON COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1278
= CASE
1279
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1280
    ELSE "*Name_matched_author"
1281
END
1282

    
1283
derived column
1284

    
1285
to modify expr:
1286
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1287
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1288
    ELSE "*Name_matched_author"
1289
END$$)::util.derived_col_def);
1290
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1291

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

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

    
1302

    
1303
--
1304
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1305
--
1306

    
1307
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1308
= CASE
1309
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1310
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1311
END
1312

    
1313
derived column
1314

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

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

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

    
1332

    
1333
--
1334
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1335
--
1336

    
1337
CREATE VIEW taxon_best_match AS
1338
 SELECT taxon_match.batch,
1339
    taxon_match.match_num,
1340
    taxon_match."*Name_number",
1341
    taxon_match."*Name_submitted",
1342
    taxon_match."*Overall_score",
1343
    taxon_match."*Name_matched",
1344
    taxon_match."*Name_matched_rank",
1345
    taxon_match."*Name_score",
1346
    taxon_match."*Name_matched_author",
1347
    taxon_match."*Name_matched_url",
1348
    taxon_match."*Author_matched",
1349
    taxon_match."*Author_score",
1350
    taxon_match."*Family_matched",
1351
    taxon_match."*Family_score",
1352
    taxon_match."*Name_matched_accepted_family",
1353
    taxon_match."*Genus_matched",
1354
    taxon_match."*Genus_score",
1355
    taxon_match."*Specific_epithet_matched",
1356
    taxon_match."*Specific_epithet_score",
1357
    taxon_match."*Infraspecific_rank",
1358
    taxon_match."*Infraspecific_epithet_matched",
1359
    taxon_match."*Infraspecific_epithet_score",
1360
    taxon_match."*Infraspecific_rank_2",
1361
    taxon_match."*Infraspecific_epithet_2_matched",
1362
    taxon_match."*Infraspecific_epithet_2_score",
1363
    taxon_match."*Annotations",
1364
    taxon_match."*Unmatched_terms",
1365
    taxon_match."*Taxonomic_status",
1366
    taxon_match."*Accepted_name",
1367
    taxon_match."*Accepted_name_author",
1368
    taxon_match."*Accepted_name_rank",
1369
    taxon_match."*Accepted_name_url",
1370
    taxon_match."*Accepted_name_species",
1371
    taxon_match."*Accepted_name_family",
1372
    taxon_match."*Selected",
1373
    taxon_match."*Source",
1374
    taxon_match."*Warnings",
1375
    taxon_match."*Accepted_name_lsid",
1376
    taxon_match.is_valid_match,
1377
    taxon_match.scrubbed_unique_taxon_name,
1378
    taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1379
    taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1380
    taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org",
1381
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1382
    taxon_match.matched_has_accepted,
1383
    taxon_match."Accepted_family__@TNRS__@vegpath.org",
1384
    taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1385
    taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}",
1386
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
1387
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1388
    taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1389
    taxon_match."__accepted_infraspecific_{rank,epithet}",
1390
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1391
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1392
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1393
    taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1394
    taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1395
    taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1396
    taxon_match."[scrubbed_]genus__@DwC__@vegpath.org",
1397
    taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1398
    taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1399
    taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1400
    taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1401
    taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1402
    taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1403
    taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1404
    taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1405
   FROM taxon_match
1406
  WHERE (taxon_match."*Selected" = 'true'::text);
1407

    
1408

    
1409
--
1410
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1411
--
1412

    
1413
COMMENT ON VIEW taxon_best_match IS '
1414
to modify:
1415
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1416
SELECT __
1417
$$);
1418
';
1419

    
1420

    
1421
--
1422
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1423
--
1424

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

    
1495

    
1496
--
1497
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1498
--
1499

    
1500
COMMENT ON VIEW "MatchedTaxon" IS '
1501
to modify:
1502
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
1503
SELECT __
1504
$$);
1505
';
1506

    
1507

    
1508
--
1509
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
1510
--
1511

    
1512
CREATE VIEW "ValidMatchedTaxon" AS
1513
 SELECT "MatchedTaxon".batch,
1514
    "MatchedTaxon".match_num,
1515
    "MatchedTaxon"."*Name_number",
1516
    "MatchedTaxon"."*Name_submitted",
1517
    "MatchedTaxon"."*Overall_score",
1518
    "MatchedTaxon"."*Name_matched",
1519
    "MatchedTaxon"."*Name_matched_rank",
1520
    "MatchedTaxon"."*Name_score",
1521
    "MatchedTaxon"."*Name_matched_author",
1522
    "MatchedTaxon"."*Name_matched_url",
1523
    "MatchedTaxon"."*Author_matched",
1524
    "MatchedTaxon"."*Author_score",
1525
    "MatchedTaxon"."*Family_matched",
1526
    "MatchedTaxon"."*Family_score",
1527
    "MatchedTaxon"."*Name_matched_accepted_family",
1528
    "MatchedTaxon"."*Genus_matched",
1529
    "MatchedTaxon"."*Genus_score",
1530
    "MatchedTaxon"."*Specific_epithet_matched",
1531
    "MatchedTaxon"."*Specific_epithet_score",
1532
    "MatchedTaxon"."*Infraspecific_rank",
1533
    "MatchedTaxon"."*Infraspecific_epithet_matched",
1534
    "MatchedTaxon"."*Infraspecific_epithet_score",
1535
    "MatchedTaxon"."*Infraspecific_rank_2",
1536
    "MatchedTaxon"."*Infraspecific_epithet_2_matched",
1537
    "MatchedTaxon"."*Infraspecific_epithet_2_score",
1538
    "MatchedTaxon"."*Annotations",
1539
    "MatchedTaxon"."*Unmatched_terms",
1540
    "MatchedTaxon"."*Taxonomic_status",
1541
    "MatchedTaxon"."*Accepted_name",
1542
    "MatchedTaxon"."*Accepted_name_author",
1543
    "MatchedTaxon"."*Accepted_name_rank",
1544
    "MatchedTaxon"."*Accepted_name_url",
1545
    "MatchedTaxon"."*Accepted_name_species",
1546
    "MatchedTaxon"."*Accepted_name_family",
1547
    "MatchedTaxon"."*Selected",
1548
    "MatchedTaxon"."*Source",
1549
    "MatchedTaxon"."*Warnings",
1550
    "MatchedTaxon"."*Accepted_name_lsid",
1551
    "MatchedTaxon".is_valid_match,
1552
    "MatchedTaxon".scrubbed_unique_taxon_name,
1553
    "MatchedTaxon"."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1554
    "MatchedTaxon"."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1555
    "MatchedTaxon"."matched~Name[_no_author]___@TNRS__@vegpath.org",
1556
    "MatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1557
    "MatchedTaxon".matched_has_accepted,
1558
    "MatchedTaxon"."Accepted_family__@TNRS__@vegpath.org",
1559
    "MatchedTaxon"."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1560
    "MatchedTaxon"."__accepted_{genus,specific_epithet,infra_{rank,epithet}}",
1561
    "MatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1562
    "MatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1563
    "MatchedTaxon"."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1564
    "MatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1565
    "MatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1566
    "MatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1567
    "MatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1568
    "MatchedTaxon"."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1569
    "MatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1570
    "MatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1571
    "MatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org",
1572
    "MatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1573
    "MatchedTaxon"."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1574
    "MatchedTaxon"."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1575
    "MatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1576
    "MatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1577
    "MatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1578
    "MatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1579
    "MatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1580
   FROM "MatchedTaxon"
1581
  WHERE "MatchedTaxon".is_valid_match;
1582

    
1583

    
1584
--
1585
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
1586
--
1587

    
1588
COMMENT ON VIEW "ValidMatchedTaxon" IS '
1589
to update, use * as the column list
1590
';
1591

    
1592

    
1593
--
1594
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1595
--
1596

    
1597
CREATE TABLE batch (
1598
    id text NOT NULL,
1599
    id_by_time text,
1600
    time_submitted timestamp with time zone DEFAULT now(),
1601
    client_version text
1602
);
1603

    
1604

    
1605
--
1606
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1607
--
1608

    
1609
CREATE TABLE batch_download_settings (
1610
    id text NOT NULL,
1611
    "E-mail" text,
1612
    "Id" text,
1613
    "Job type" text,
1614
    "Contains Id" boolean,
1615
    "Start time" text,
1616
    "Finish time" text,
1617
    "TNRS version" text,
1618
    "Sources selected" text,
1619
    "Match threshold" double precision,
1620
    "Classification" text,
1621
    "Allow partial matches?" boolean,
1622
    "Sort by source" boolean,
1623
    "Constrain by higher taxonomy" boolean
1624
);
1625

    
1626

    
1627
--
1628
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
1629
--
1630

    
1631
COMMENT ON TABLE batch_download_settings IS '
1632
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
1633
';
1634

    
1635

    
1636
--
1637
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1638
--
1639

    
1640
CREATE TABLE client_version (
1641
    id text NOT NULL,
1642
    global_rev integer NOT NULL,
1643
    "/lib/tnrs.py rev" integer,
1644
    "/bin/tnrs_db rev" integer
1645
);
1646

    
1647

    
1648
--
1649
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
1650
--
1651

    
1652
COMMENT ON TABLE client_version IS '
1653
contains svn revisions
1654
';
1655

    
1656

    
1657
--
1658
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
1659
--
1660

    
1661
COMMENT ON COLUMN client_version.global_rev IS '
1662
from `svn info .` > Last Changed Rev
1663
';
1664

    
1665

    
1666
--
1667
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
1668
--
1669

    
1670
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
1671
from `svn info lib/tnrs.py` > Last Changed Rev
1672
';
1673

    
1674

    
1675
--
1676
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
1677
--
1678

    
1679
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
1680
from `svn info bin/tnrs_db` > Last Changed Rev
1681
';
1682

    
1683

    
1684
--
1685
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1686
--
1687

    
1688
CREATE VIEW taxon_match_input AS
1689
 SELECT taxon_match."*Name_number" AS "Name_number",
1690
    taxon_match."*Name_submitted" AS "Name_submitted",
1691
    taxon_match."*Overall_score" AS "Overall_score",
1692
    taxon_match."*Name_matched" AS "Name_matched",
1693
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1694
    taxon_match."*Name_score" AS "Name_score",
1695
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1696
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1697
    taxon_match."*Author_matched" AS "Author_matched",
1698
    taxon_match."*Author_score" AS "Author_score",
1699
    taxon_match."*Family_matched" AS "Family_matched",
1700
    taxon_match."*Family_score" AS "Family_score",
1701
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1702
    taxon_match."*Genus_matched" AS "Genus_matched",
1703
    taxon_match."*Genus_score" AS "Genus_score",
1704
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1705
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1706
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1707
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1708
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1709
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1710
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1711
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1712
    taxon_match."*Annotations" AS "Annotations",
1713
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1714
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1715
    taxon_match."*Accepted_name" AS "Accepted_name",
1716
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1717
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1718
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1719
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1720
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1721
    taxon_match."*Selected" AS "Selected",
1722
    taxon_match."*Source" AS "Source",
1723
    taxon_match."*Warnings" AS "Warnings",
1724
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1725
   FROM taxon_match;
1726

    
1727

    
1728
--
1729
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace: 
1730
--
1731

    
1732
CREATE TABLE taxon_match_input__copy_to (
1733
    "Name_number" integer,
1734
    "Name_submitted" text,
1735
    "Overall_score" double precision,
1736
    "Name_matched" text,
1737
    "Name_matched_rank" text,
1738
    "Name_score" double precision,
1739
    "Name_matched_author" text,
1740
    "Name_matched_url" text,
1741
    "Author_matched" text,
1742
    "Author_score" double precision,
1743
    "Family_matched" text,
1744
    "Family_score" double precision,
1745
    "Name_matched_accepted_family" text,
1746
    "Genus_matched" text,
1747
    "Genus_score" double precision,
1748
    "Specific_epithet_matched" text,
1749
    "Specific_epithet_score" double precision,
1750
    "Infraspecific_rank" text,
1751
    "Infraspecific_epithet_matched" text,
1752
    "Infraspecific_epithet_score" double precision,
1753
    "Infraspecific_rank_2" text,
1754
    "Infraspecific_epithet_2_matched" text,
1755
    "Infraspecific_epithet_2_score" double precision,
1756
    "Annotations" text,
1757
    "Unmatched_terms" text,
1758
    "Taxonomic_status" text,
1759
    "Accepted_name" text,
1760
    "Accepted_name_author" text,
1761
    "Accepted_name_rank" text,
1762
    "Accepted_name_url" text,
1763
    "Accepted_name_species" text,
1764
    "Accepted_name_family" text,
1765
    "Selected" text,
1766
    "Source" text,
1767
    "Warnings" text,
1768
    "Accepted_name_lsid" text
1769
);
1770

    
1771

    
1772
--
1773
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1774
--
1775

    
1776
CREATE VIEW taxon_scrub AS
1777
 SELECT "ValidMatchedTaxon".batch,
1778
    "ValidMatchedTaxon".match_num,
1779
    "ValidMatchedTaxon"."*Name_number",
1780
    "ValidMatchedTaxon"."*Name_submitted",
1781
    "ValidMatchedTaxon"."*Overall_score",
1782
    "ValidMatchedTaxon"."*Name_matched",
1783
    "ValidMatchedTaxon"."*Name_matched_rank",
1784
    "ValidMatchedTaxon"."*Name_score",
1785
    "ValidMatchedTaxon"."*Name_matched_author",
1786
    "ValidMatchedTaxon"."*Name_matched_url",
1787
    "ValidMatchedTaxon"."*Author_matched",
1788
    "ValidMatchedTaxon"."*Author_score",
1789
    "ValidMatchedTaxon"."*Family_matched",
1790
    "ValidMatchedTaxon"."*Family_score",
1791
    "ValidMatchedTaxon"."*Name_matched_accepted_family",
1792
    "ValidMatchedTaxon"."*Genus_matched",
1793
    "ValidMatchedTaxon"."*Genus_score",
1794
    "ValidMatchedTaxon"."*Specific_epithet_matched",
1795
    "ValidMatchedTaxon"."*Specific_epithet_score",
1796
    "ValidMatchedTaxon"."*Infraspecific_rank",
1797
    "ValidMatchedTaxon"."*Infraspecific_epithet_matched",
1798
    "ValidMatchedTaxon"."*Infraspecific_epithet_score",
1799
    "ValidMatchedTaxon"."*Infraspecific_rank_2",
1800
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_matched",
1801
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_score",
1802
    "ValidMatchedTaxon"."*Annotations",
1803
    "ValidMatchedTaxon"."*Unmatched_terms",
1804
    "ValidMatchedTaxon"."*Taxonomic_status",
1805
    "ValidMatchedTaxon"."*Accepted_name",
1806
    "ValidMatchedTaxon"."*Accepted_name_author",
1807
    "ValidMatchedTaxon"."*Accepted_name_rank",
1808
    "ValidMatchedTaxon"."*Accepted_name_url",
1809
    "ValidMatchedTaxon"."*Accepted_name_species",
1810
    "ValidMatchedTaxon"."*Accepted_name_family",
1811
    "ValidMatchedTaxon"."*Selected",
1812
    "ValidMatchedTaxon"."*Source",
1813
    "ValidMatchedTaxon"."*Warnings",
1814
    "ValidMatchedTaxon"."*Accepted_name_lsid",
1815
    "ValidMatchedTaxon".is_valid_match,
1816
    "ValidMatchedTaxon".scrubbed_unique_taxon_name,
1817
    "ValidMatchedTaxon"."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1818
    "ValidMatchedTaxon"."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1819
    "ValidMatchedTaxon"."matched~Name[_no_author]___@TNRS__@vegpath.org",
1820
    "ValidMatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1821
    "ValidMatchedTaxon".matched_has_accepted,
1822
    "ValidMatchedTaxon"."Accepted_family__@TNRS__@vegpath.org",
1823
    "ValidMatchedTaxon"."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1824
    "ValidMatchedTaxon"."__accepted_{genus,specific_epithet,infra_{rank,epithet}}",
1825
    "ValidMatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1826
    "ValidMatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1827
    "ValidMatchedTaxon"."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1828
    "ValidMatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1829
    "ValidMatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1830
    "ValidMatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1831
    "ValidMatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1832
    "ValidMatchedTaxon"."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1833
    "ValidMatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1834
    "ValidMatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1835
    "ValidMatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org",
1836
    "ValidMatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1837
    "ValidMatchedTaxon"."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1838
    "ValidMatchedTaxon"."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1839
    "ValidMatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1840
    "ValidMatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1841
    "ValidMatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1842
    "ValidMatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1843
    "ValidMatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org",
1844
        CASE
1845
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]taxonRank__@DwC__@vegpath.org"
1846
            ELSE NULL::text
1847
        END AS scrubbed_taxon_rank,
1848
        CASE
1849
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"
1850
            ELSE NULL::text
1851
        END AS scrubbed_family,
1852
        CASE
1853
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]genus__@DwC__@vegpath.org"
1854
            ELSE NULL::text
1855
        END AS scrubbed_genus,
1856
        CASE
1857
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]specificEpithet__@DwC__@vegpath.org"
1858
            ELSE NULL::text
1859
        END AS scrubbed_specific_epithet,
1860
        CASE
1861
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1862
            ELSE NULL::text
1863
        END AS scrubbed_infraspecific_rank,
1864
        CASE
1865
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"
1866
            ELSE NULL::text
1867
        END AS scrubbed_infraspecific_epithet,
1868
        CASE
1869
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org"
1870
            ELSE NULL::text
1871
        END AS scrubbed_author,
1872
        CASE
1873
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"
1874
            ELSE NULL::text
1875
        END AS scrubbed_taxon_name_no_author,
1876
        CASE
1877
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1878
            ELSE NULL::text
1879
        END AS scrubbed_taxon_name_with_author,
1880
        CASE
1881
            WHEN true THEN "ValidMatchedTaxon"."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"
1882
            ELSE NULL::text
1883
        END AS scrubbed_morphospecies_binomial
1884
   FROM "ValidMatchedTaxon";
1885

    
1886

    
1887
--
1888
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1889
--
1890

    
1891
COMMENT ON VIEW taxon_scrub IS '
1892
to modify:
1893
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1894
SELECT __
1895
$$);
1896
';
1897

    
1898

    
1899
--
1900
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1901
--
1902

    
1903
ALTER TABLE ONLY batch_download_settings
1904
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1905

    
1906

    
1907
--
1908
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1909
--
1910

    
1911
ALTER TABLE ONLY batch
1912
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1913

    
1914

    
1915
--
1916
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1917
--
1918

    
1919
ALTER TABLE ONLY batch
1920
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1921

    
1922

    
1923
--
1924
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1925
--
1926

    
1927
ALTER TABLE ONLY client_version
1928
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1929

    
1930

    
1931
--
1932
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace: 
1933
--
1934

    
1935
ALTER TABLE ONLY taxon_match
1936
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1937

    
1938
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1939

    
1940

    
1941
--
1942
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1943
--
1944

    
1945
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1946

    
1947

    
1948
--
1949
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1950
--
1951

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

    
1954

    
1955
--
1956
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1957
--
1958

    
1959
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1960

    
1961

    
1962
--
1963
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace: 
1964
--
1965

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

    
1968

    
1969
--
1970
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1971
--
1972

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

    
1975

    
1976
--
1977
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1978
--
1979

    
1980
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1981

    
1982

    
1983
--
1984
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1985
--
1986

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

    
1989

    
1990
--
1991
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1992
--
1993

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

    
1996

    
1997
--
1998
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1999
--
2000

    
2001
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
2002

    
2003

    
2004
--
2005
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
2006
--
2007

    
2008
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();
2009

    
2010

    
2011
--
2012
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
2013
--
2014

    
2015
ALTER TABLE ONLY batch
2016
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
2017

    
2018

    
2019
--
2020
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
2021
--
2022

    
2023
ALTER TABLE ONLY batch_download_settings
2024
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
2025

    
2026

    
2027
--
2028
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
2029
--
2030

    
2031
ALTER TABLE ONLY taxon_match
2032
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
2033

    
2034

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

    
2039
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
2040
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
2041
GRANT ALL ON SCHEMA "TNRS" TO bien;
2042
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
2043

    
2044

    
2045
--
2046
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
2047
--
2048

    
2049
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
2050
REVOKE ALL ON TABLE taxon_match FROM bien;
2051
GRANT ALL ON TABLE taxon_match TO bien;
2052
GRANT SELECT ON TABLE taxon_match TO bien_read;
2053

    
2054

    
2055
--
2056
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
2057
--
2058

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

    
2064

    
2065
--
2066
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
2067
--
2068

    
2069
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
2070
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
2071
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
2072
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
2073

    
2074

    
2075
--
2076
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
2077
--
2078

    
2079
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
2080
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
2081
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
2082
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
2083

    
2084

    
2085
--
2086
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
2087
--
2088

    
2089
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
2090
REVOKE ALL ON TABLE taxon_match_input FROM bien;
2091
GRANT ALL ON TABLE taxon_match_input TO bien;
2092
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
2093

    
2094

    
2095
--
2096
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
2097
--
2098

    
2099
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
2100
REVOKE ALL ON TABLE taxon_scrub FROM bien;
2101
GRANT ALL ON TABLE taxon_scrub TO bien;
2102
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
2103

    
2104

    
2105
--
2106
-- PostgreSQL database dump complete
2107
--
2108

    
(7-7/9)