Project

General

Profile

1 10778 aaronmk
--
2
-- PostgreSQL database dump
3
--
4 10737 aaronmk
5 10778 aaronmk
SET statement_timeout = 0;
6 11708 aaronmk
SET lock_timeout = 0;
7 10778 aaronmk
SET client_encoding = 'UTF8';
8
SET standard_conforming_strings = on;
9
SET check_function_bodies = false;
10
SET client_min_messages = warning;
11
12 10737 aaronmk
--
13 10778 aaronmk
-- Name: TNRS; Type: SCHEMA; Schema: -; Owner: -
14
--
15 10737 aaronmk
16 10778 aaronmk
--CREATE SCHEMA "TNRS";
17 10725 aaronmk
18
19 11614 aaronmk
--
20
-- Name: SCHEMA "TNRS"; Type: COMMENT; Schema: -; Owner: -
21
--
22
23 13575 aaronmk
COMMENT ON SCHEMA "TNRS" IS '
24
IMPORTANT: when changing this schema, you must also make the same changes on vegbiendev:
25 11617 aaronmk
on vegbiendev:
26
# back up existing TNRS schema (in case of an accidental incorrect change):
27 11614 aaronmk
$ make backups/TNRS.backup-remake # runtime: 3 min ("real 2m44.277s")
28 11616 aaronmk
$ svn up
29
$ svn di
30
# make the changes shown in the diff
31
## to change column types:
32 13861 aaronmk
SELECT util.set_col_types(''"TNRS".taxon_match'', ARRAY[
33 11614 aaronmk
  (''col'', ''new_type'')
34 11616 aaronmk
]::util.col_cast[]); -- runtime: 9 min ("531282 ms")
35 11617 aaronmk
$ rm=1 inputs/.TNRS/schema.sql.run
36
# repeat until `svn di` shows no diff
37
# back up new TNRS schema:
38 13575 aaronmk
$ make backups/TNRS.backup-remake # runtime: 3 min ("real 2m44.277s")
39
';
40 11614 aaronmk
41
42 10778 aaronmk
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 10728 aaronmk
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 10778 aaronmk
$$;
57 10728 aaronmk
58
59
--
60 10778 aaronmk
-- Name: family_is_homonym(text); Type: FUNCTION; Schema: TNRS; Owner: -
61
--
62 10728 aaronmk
63 10778 aaronmk
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 10736 aaronmk
69 10778 aaronmk
70 10736 aaronmk
--
71 10778 aaronmk
-- Name: genus_is_homonym(text); Type: FUNCTION; Schema: TNRS; Owner: -
72
--
73 10736 aaronmk
74 10778 aaronmk
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 7844 aaronmk
80 9985 aaronmk
81 10778 aaronmk
--
82 11709 aaronmk
-- Name: map_taxonomic_status(text, text); Type: FUNCTION; Schema: TNRS; Owner: -
83
--
84
85 13503 aaronmk
CREATE FUNCTION map_taxonomic_status(taxonomic_status_verbatim text, accepted_taxon_name_no_author text) RETURNS text
86 11709 aaronmk
    LANGUAGE sql IMMUTABLE
87
    AS $_$
88 13503 aaronmk
/* 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 11709 aaronmk
SELECT CASE WHEN $2 IS NOT NULL THEN 'accepted' ELSE lower($1) END
92
$_$;
93
94
95
--
96 14356 aaronmk
-- Name: remove_prefix(text, text, boolean, boolean); Type: FUNCTION; Schema: TNRS; Owner: -
97 14347 aaronmk
--
98
99 14356 aaronmk
CREATE FUNCTION remove_prefix(prefix text, str text, require boolean DEFAULT true, case_sensitive boolean DEFAULT true) RETURNS text
100 14347 aaronmk
    LANGUAGE sql IMMUTABLE
101
    AS $$
102 14358 aaronmk
SELECT util.remove_prefix(prefix, str, require, case_sensitive)
103 14347 aaronmk
$$;
104
105
106
--
107 14356 aaronmk
-- Name: FUNCTION remove_prefix(prefix text, str text, require boolean, case_sensitive boolean); Type: COMMENT; Schema: TNRS; Owner: -
108 14347 aaronmk
--
109
110 14356 aaronmk
COMMENT ON FUNCTION remove_prefix(prefix text, str text, require boolean, case_sensitive boolean) IS '
111 14347 aaronmk
wrapper that prevents views from getting dropped when the util schema is reinstalled
112
';
113
114
115
--
116 13868 aaronmk
-- Name: taxon_match__batch_begin(); Type: FUNCTION; Schema: TNRS; Owner: -
117 13866 aaronmk
--
118
119 13868 aaronmk
CREATE FUNCTION taxon_match__batch_begin() RETURNS trigger
120 13866 aaronmk
    LANGUAGE plpgsql
121
    AS $$
122
BEGIN
123 13869 aaronmk
	PERFORM util.seq__reset('pg_temp.taxon_match__match_num__seq', 0);
124 13567 aaronmk
	RETURN NULL;
125
END;
126
$$;
127
128
129
--
130 13868 aaronmk
-- Name: taxon_match__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
131 13578 aaronmk
--
132
133 13868 aaronmk
CREATE FUNCTION taxon_match__fill() RETURNS trigger
134 13578 aaronmk
    LANGUAGE plpgsql
135
    AS $$
136 11643 aaronmk
BEGIN
137 13871 aaronmk
	DECLARE
138
		"Specific_epithet_is_plant" boolean :=
139 11628 aaronmk
			(CASE
140 14111 aaronmk
			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 13871 aaronmk
				THEN true
144
			ELSE NULL -- ambiguous
145
			END);
146 14111 aaronmk
		never_homonym boolean = COALESCE(new."*Author_score" >= 0.6, false);
147 13871 aaronmk
			-- author disambiguates
148
		family_is_homonym boolean = NOT never_homonym
149 14111 aaronmk
			AND "TNRS".family_is_homonym(new."*Family_matched");
150 13871 aaronmk
		genus_is_homonym  boolean = NOT never_homonym
151 14111 aaronmk
			AND "TNRS".genus_is_homonym(new."*Genus_matched");
152 13871 aaronmk
	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 14111 aaronmk
		new.is_valid_match = new."*Taxonomic_status" != 'Invalid'
156 13871 aaronmk
			AND COALESCE(CASE
157 14111 aaronmk
			WHEN new."*Family_score" = 1 AND NOT family_is_homonym -- exact match
158 13871 aaronmk
				THEN true
159
			ELSE -- consider genus
160 11628 aaronmk
				(CASE
161 14111 aaronmk
				WHEN new."*Genus_score" =  1	   -- exact match
162 13871 aaronmk
					THEN
163
					(CASE
164
					WHEN NOT genus_is_homonym THEN true
165
					ELSE "Specific_epithet_is_plant"
166
					END)
167 14111 aaronmk
				WHEN new."*Genus_score" >= 0.85 -- fuzzy match
168 13871 aaronmk
					THEN "Specific_epithet_is_plant"
169
				ELSE NULL -- ambiguous
170 11628 aaronmk
				END)
171 13871 aaronmk
			END, false);
172
	END;
173 11628 aaronmk
174 13871 aaronmk
	DECLARE
175
		matched_taxon_name_with_author text = NULLIF(concat_ws(' '
176 14111 aaronmk
			, 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 13871 aaronmk
			), '');
181
		accepted_taxon_name_with_author text = NULLIF(concat_ws(' '
182 14111 aaronmk
			, NULLIF(NULLIF(new."*Accepted_name_family", 'Unknown'),
183
				new."*Accepted_name")
184
			, new."*Accepted_name"
185
			, new."*Accepted_name_author"
186 13871 aaronmk
			), '');
187
	BEGIN
188
		new.scrubbed_unique_taxon_name = COALESCE(
189
			accepted_taxon_name_with_author, matched_taxon_name_with_author);
190
	END;
191
192 11628 aaronmk
	RETURN new;
193 7134 aaronmk
END;
194 10778 aaronmk
$$;
195
196
197
--
198 13868 aaronmk
-- Name: FUNCTION taxon_match__fill(); Type: COMMENT; Schema: TNRS; Owner: -
199 10778 aaronmk
--
200
201 13868 aaronmk
COMMENT ON FUNCTION taxon_match__fill() IS '
202 13575 aaronmk
IMPORTANT: when changing this function, you must regenerate the derived cols:
203 13861 aaronmk
UPDATE "TNRS".taxon_match SET "Name_submitted" = "Name_submitted"
204 11715 aaronmk
runtime: 30 min ("5564082 rows affected, 1918900 ms execution time")
205 13861 aaronmk
VACUUM ANALYZE "TNRS".taxon_match -- to remove previous rows
206 13575 aaronmk
runtime: 1.5 min ("92633 ms")
207
';
208 7134 aaronmk
209 7251 aaronmk
210 13631 aaronmk
--
211 14122 aaronmk
-- 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 14309 aaronmk
	-- clear derived cols so old values won't be used in calculations
219 14311 aaronmk
	new."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" = NULL;
220 14309 aaronmk
	new."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" = NULL;
221 14330 aaronmk
	new."matched~Name[_no_author]___@TNRS__@vegpath.org" = NULL;
222 14309 aaronmk
	new."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" = NULL;
223
	new.matched_has_accepted = NULL;
224 14318 aaronmk
	new."Accepted_family__@TNRS__@vegpath.org" = NULL;
225 14366 aaronmk
	new."Accepted_species[_binomial]__@TNRS__@vegpath.org" = NULL;
226 14376 aaronmk
	new."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" = NULL;
227 14309 aaronmk
	new."[accepted_]genus__@DwC__@vegpath.org" = NULL;
228
	new."[accepted_]specificEpithet__@DwC__@vegpath.org" = NULL;
229 14311 aaronmk
	new."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" = NULL;
230 14309 aaronmk
	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 14328 aaronmk
	new."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" = NULL;
235 14309 aaronmk
	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 14328 aaronmk
	new."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" = NULL;
241 14309 aaronmk
	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 14311 aaronmk
	new."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" = (SELECT "*Unmatched_terms" FROM (SELECT new.*) new);
249 14308 aaronmk
	new."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT ("*Genus_matched" || ' '::text) || "*Specific_epithet_matched" FROM (SELECT new.*) new);
250 14330 aaronmk
	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 14308 aaronmk
	new.matched_has_accepted = (SELECT "*Accepted_name" IS NOT NULL FROM (SELECT new.*) new);
253 14318 aaronmk
	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 14366 aaronmk
	new."Accepted_species[_binomial]__@TNRS__@vegpath.org" = (SELECT rtrim("*Accepted_name_species", ' '::text) FROM (SELECT new.*) new);
259 14376 aaronmk
	new."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" = (SELECT regexp_split_to_array("*Accepted_name", ' '::text) FROM (SELECT new.*) new);
260 14377 aaronmk
	new."[accepted_]genus__@DwC__@vegpath.org" = (SELECT "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1] FROM (SELECT new.*) new);
261 14376 aaronmk
	new."[accepted_]specificEpithet__@DwC__@vegpath.org" = (SELECT "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2] FROM (SELECT new.*) new);
262 14311 aaronmk
	new."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" = (SELECT CASE
263 14323 aaronmk
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
264 14327 aaronmk
    WHEN ("*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
265 14367 aaronmk
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
266 14311 aaronmk
END FROM (SELECT new.*) new);
267 14378 aaronmk
	new."__accepted_infraspecific_{rank,epithet}" = (SELECT NULLIF("__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[3:4], '{}'::text[]) FROM (SELECT new.*) new);
268 14308 aaronmk
	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 14328 aaronmk
	new."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" = (SELECT "TNRS".map_taxonomic_status("*Taxonomic_status", "*Accepted_name") FROM (SELECT new.*) new);
272 14308 aaronmk
	new."[scrubbed_]taxonRank__@DwC__@vegpath.org" = (SELECT CASE
273 14282 aaronmk
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
274
    ELSE "*Name_matched_rank"
275 14308 aaronmk
END FROM (SELECT new.*) new);
276
	new."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
277 14323 aaronmk
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
278 14282 aaronmk
    ELSE "*Name_matched_accepted_family"
279 14308 aaronmk
END FROM (SELECT new.*) new);
280
	new."[scrubbed_]genus__@DwC__@vegpath.org" = (SELECT CASE
281 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
282
    ELSE "*Genus_matched"
283 14308 aaronmk
END FROM (SELECT new.*) new);
284
	new."[scrubbed_]specificEpithet__@DwC__@vegpath.org" = (SELECT CASE
285 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
286
    ELSE "*Specific_epithet_matched"
287 14308 aaronmk
END FROM (SELECT new.*) new);
288
	new."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
289 14367 aaronmk
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
290 14282 aaronmk
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
291 14308 aaronmk
END FROM (SELECT new.*) new);
292 14328 aaronmk
	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 14308 aaronmk
	new."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = (SELECT CASE
298 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
299
    ELSE "*Infraspecific_rank"
300 14308 aaronmk
END FROM (SELECT new.*) new);
301
	new."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" = (SELECT CASE
302 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
303
    ELSE "*Infraspecific_epithet_matched"
304 14308 aaronmk
END FROM (SELECT new.*) new);
305
	new."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
306 14282 aaronmk
    WHEN matched_has_accepted THEN "*Accepted_name"
307 14330 aaronmk
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
308 14308 aaronmk
END FROM (SELECT new.*) new);
309
	new."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" = (SELECT CASE
310 14282 aaronmk
    WHEN matched_has_accepted THEN "*Accepted_name_author"
311
    ELSE "*Name_matched_author"
312 14308 aaronmk
END FROM (SELECT new.*) new);
313
	new."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT CASE
314 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
315
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
316 14308 aaronmk
END FROM (SELECT new.*) new);
317 14304 aaronmk
318 14122 aaronmk
	RETURN new;
319
END;
320
$$;
321
322
323
--
324 14254 aaronmk
-- 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 13868 aaronmk
-- 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 13869 aaronmk
		new.match_num = "TNRS".taxon_match__match_num__next();
345 13868 aaronmk
	END IF;
346
	RETURN new;
347
END;
348
$$;
349
350
351
--
352 13869 aaronmk
-- 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 13868 aaronmk
-- 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 13631 aaronmk
-- 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 13686 aaronmk
]::text[]
396 13631 aaronmk
$$;
397
398
399 10778 aaronmk
SET default_tablespace = '';
400
401
SET default_with_oids = false;
402
403 10728 aaronmk
--
404 14436 aaronmk
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
405
--
406
407
CREATE TABLE batch (
408
    id text NOT NULL,
409
    id_by_time text,
410
    time_submitted timestamp with time zone DEFAULT now(),
411
    client_version text
412
);
413
414
415
--
416
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
417
--
418
419
CREATE TABLE batch_download_settings (
420
    id text NOT NULL,
421
    "E-mail" text,
422
    "Id" text,
423
    "Job type" text,
424
    "Contains Id" boolean,
425
    "Start time" text,
426
    "Finish time" text,
427
    "TNRS version" text,
428
    "Sources selected" text,
429
    "Match threshold" double precision,
430
    "Classification" text,
431
    "Allow partial matches?" boolean,
432
    "Sort by source" boolean,
433
    "Constrain by higher taxonomy" boolean
434
);
435
436
437
--
438
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
439
--
440
441
COMMENT ON TABLE batch_download_settings IS '
442
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
443
';
444
445
446
--
447
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
448
--
449
450
CREATE TABLE client_version (
451
    id text NOT NULL,
452
    global_rev integer NOT NULL,
453
    "/lib/tnrs.py rev" integer,
454
    "/bin/tnrs_db rev" integer
455
);
456
457
458
--
459
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
460
--
461
462
COMMENT ON TABLE client_version IS '
463
contains svn revisions
464
';
465
466
467
--
468
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
469
--
470
471
COMMENT ON COLUMN client_version.global_rev IS '
472
from `svn info .` > Last Changed Rev
473
';
474
475
476
--
477
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
478
--
479
480
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
481
from `svn info lib/tnrs.py` > Last Changed Rev
482
';
483
484
485
--
486
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
487
--
488
489
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
490
from `svn info bin/tnrs_db` > Last Changed Rev
491
';
492
493
494
--
495 13861 aaronmk
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
496 10778 aaronmk
--
497 7251 aaronmk
498 13861 aaronmk
CREATE TABLE taxon_match (
499 10778 aaronmk
    batch text DEFAULT now() NOT NULL,
500 13580 aaronmk
    match_num integer NOT NULL,
501 14111 aaronmk
    "*Name_number" integer NOT NULL,
502
    "*Name_submitted" text NOT NULL,
503
    "*Overall_score" double precision,
504
    "*Name_matched" text,
505
    "*Name_matched_rank" text,
506
    "*Name_score" double precision,
507
    "*Name_matched_author" text,
508
    "*Name_matched_url" text,
509
    "*Author_matched" text,
510
    "*Author_score" double precision,
511
    "*Family_matched" text,
512
    "*Family_score" double precision,
513
    "*Name_matched_accepted_family" text,
514
    "*Genus_matched" text,
515
    "*Genus_score" double precision,
516
    "*Specific_epithet_matched" text,
517
    "*Specific_epithet_score" double precision,
518
    "*Infraspecific_rank" text,
519
    "*Infraspecific_epithet_matched" text,
520
    "*Infraspecific_epithet_score" double precision,
521
    "*Infraspecific_rank_2" text,
522
    "*Infraspecific_epithet_2_matched" text,
523
    "*Infraspecific_epithet_2_score" double precision,
524
    "*Annotations" text,
525
    "*Unmatched_terms" text,
526
    "*Taxonomic_status" text,
527
    "*Accepted_name" text,
528
    "*Accepted_name_author" text,
529
    "*Accepted_name_rank" text,
530
    "*Accepted_name_url" text,
531
    "*Accepted_name_species" text,
532
    "*Accepted_name_family" text,
533
    "*Selected" text,
534
    "*Source" text,
535
    "*Warnings" text,
536
    "*Accepted_name_lsid" text,
537 11628 aaronmk
    is_valid_match boolean NOT NULL,
538 14122 aaronmk
    scrubbed_unique_taxon_name text,
539 14310 aaronmk
    "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" text,
540 14279 aaronmk
    "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" text,
541 14329 aaronmk
    "matched~Name[_no_author]___@TNRS__@vegpath.org" text,
542 14279 aaronmk
    "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" text,
543
    matched_has_accepted boolean,
544 14318 aaronmk
    "Accepted_family__@TNRS__@vegpath.org" text,
545 14366 aaronmk
    "Accepted_species[_binomial]__@TNRS__@vegpath.org" text,
546 14376 aaronmk
    "__accepted_{genus,specific_epithet,infra_{rank,epithet}}" text[],
547 14257 aaronmk
    "[accepted_]genus__@DwC__@vegpath.org" text,
548
    "[accepted_]specificEpithet__@DwC__@vegpath.org" text,
549 14310 aaronmk
    "[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" text,
550 14265 aaronmk
    "__accepted_infraspecific_{rank,epithet}" text[],
551 14266 aaronmk
    "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
552
    "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" text,
553 14267 aaronmk
    "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" text,
554 14328 aaronmk
    "[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" text,
555 14281 aaronmk
    "[scrubbed_]taxonRank__@DwC__@vegpath.org" text,
556
    "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" text,
557
    "[scrubbed_]genus__@DwC__@vegpath.org" text,
558
    "[scrubbed_]specificEpithet__@DwC__@vegpath.org" text,
559
    "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" text,
560 14328 aaronmk
    "[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" text,
561 14281 aaronmk
    "[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
562
    "[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" text,
563
    "[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" text,
564
    "[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" text,
565
    "[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" text,
566 14318 aaronmk
    CONSTRAINT "Accepted_family__@TNRS__@vegpath.org" CHECK ((NOT ("Accepted_family__@TNRS__@vegpath.org" IS DISTINCT FROM COALESCE("*Accepted_name_family",
567
CASE
568
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN "*Accepted_name"
569
    ELSE NULL::text
570
END)))),
571 14366 aaronmk
    CONSTRAINT "Accepted_species[_binomial]__@TNRS__@vegpath.org" CHECK ((NOT ("Accepted_species[_binomial]__@TNRS__@vegpath.org" IS DISTINCT FROM rtrim("*Accepted_name_species", ' '::text)))),
572 14266 aaronmk
    CONSTRAINT "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" CHECK ((NOT ("[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS DISTINCT FROM "__accepted_infraspecific_{rank,epithet}"[1]))),
573 14377 aaronmk
    CONSTRAINT "[accepted_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]genus__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]))),
574 14266 aaronmk
    CONSTRAINT "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_infraspecific_{rank,epithet}"[2]))),
575 14304 aaronmk
    CONSTRAINT "[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" CHECK ((NOT ("[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS DISTINCT FROM
576
CASE
577 14323 aaronmk
    WHEN ("*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
578 14327 aaronmk
    WHEN ("*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
579 14367 aaronmk
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
580 14304 aaronmk
END))),
581 14267 aaronmk
    CONSTRAINT "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM ("*Accepted_name" || COALESCE((' '::text || "*Accepted_name_author"), ''::text))))),
582 14376 aaronmk
    CONSTRAINT "[accepted_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]))),
583 14330 aaronmk
    CONSTRAINT "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM ("matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE((' '::text || "*Name_matched_author"), ''::text))))),
584 14278 aaronmk
    CONSTRAINT "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM (("*Genus_matched" || ' '::text) || "*Specific_epithet_matched")))),
585 14303 aaronmk
    CONSTRAINT "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" CHECK ((NOT ("[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS DISTINCT FROM "*Unmatched_terms"))),
586 14281 aaronmk
    CONSTRAINT "[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS DISTINCT FROM
587
CASE
588
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
589
    ELSE "*Infraspecific_rank"
590
END))),
591
    CONSTRAINT "[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
592
CASE
593
    WHEN matched_has_accepted THEN "*Accepted_name_author"
594
    ELSE "*Name_matched_author"
595
END))),
596
    CONSTRAINT "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
597
CASE
598 14323 aaronmk
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
599 14281 aaronmk
    ELSE "*Name_matched_accepted_family"
600
END))),
601
    CONSTRAINT "[scrubbed_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]genus__@DwC__@vegpath.org" IS DISTINCT FROM
602
CASE
603
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
604
    ELSE "*Genus_matched"
605
END))),
606
    CONSTRAINT "[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM
607
CASE
608
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
609
    ELSE "*Infraspecific_epithet_matched"
610
END))),
611 14326 aaronmk
    CONSTRAINT "[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" CHECK ((NOT ("[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS DISTINCT FROM
612
CASE
613
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'family'::text) THEN concat_ws(' '::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
614
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = 'genus'::text) THEN concat_ws(' '::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
615
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
616
END))),
617 14281 aaronmk
    CONSTRAINT "[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
618
CASE
619
    WHEN matched_has_accepted THEN "*Accepted_name"
620 14330 aaronmk
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
621 14281 aaronmk
END))),
622
    CONSTRAINT "[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM
623
CASE
624
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
625
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
626
END))),
627
    CONSTRAINT "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" CHECK ((NOT ("[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS DISTINCT FROM
628
CASE
629 14367 aaronmk
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
630 14281 aaronmk
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
631
END))),
632
    CONSTRAINT "[scrubbed_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM
633
CASE
634
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
635
    ELSE "*Specific_epithet_matched"
636
END))),
637
    CONSTRAINT "[scrubbed_]taxonRank__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]taxonRank__@DwC__@vegpath.org" IS DISTINCT FROM
638
CASE
639
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
640
    ELSE "*Name_matched_rank"
641
END))),
642 14324 aaronmk
    CONSTRAINT "[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" CHECK ((NOT ("[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" IS DISTINCT FROM map_taxonomic_status("*Taxonomic_status", "*Accepted_name")))),
643 14378 aaronmk
    CONSTRAINT "__accepted_infraspecific_{rank,epithet}" CHECK ((NOT ("__accepted_infraspecific_{rank,epithet}" IS DISTINCT FROM NULLIF("__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[3:4], '{}'::text[])))),
644 14376 aaronmk
    CONSTRAINT "__accepted_{genus,specific_epithet,infra_{rank,epithet}}" CHECK ((NOT ("__accepted_{genus,specific_epithet,infra_{rank,epithet}}" IS DISTINCT FROM regexp_split_to_array("*Accepted_name", ' '::text)))),
645 14329 aaronmk
    CONSTRAINT matched_has_accepted CHECK ((NOT (matched_has_accepted IS DISTINCT FROM ("*Accepted_name" IS NOT NULL)))),
646
    CONSTRAINT "matched~Name[_no_author]___@TNRS__@vegpath.org" CHECK ((NOT ("matched~Name[_no_author]___@TNRS__@vegpath.org" IS DISTINCT FROM NULLIF("*Name_matched", 'No suitable matches found.'::text))))
647 10778 aaronmk
);
648 7823 aaronmk
649 9759 aaronmk
650 10778 aaronmk
--
651 13861 aaronmk
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
652 10778 aaronmk
--
653 7823 aaronmk
654 13861 aaronmk
COMMENT ON TABLE taxon_match IS '
655 14161 aaronmk
whenever columns are renamed:
656 14312 aaronmk
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
657 14161 aaronmk
658 14332 aaronmk
to port derived column changes to vegbiendev:
659
SELECT util.derived_cols_export(''"TNRS".taxon_match'');
660
# run the returned SQL on vegbiendev
661 14417 aaronmk
	-- runtime: 6 h, 2.6 ms/row ("22030570 ms"; "rows=8353235")
662 14361 aaronmk
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
663 14332 aaronmk
664 14364 aaronmk
to add a new derived column:
665
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''col''), $$
666
expr
667
$$));
668
SELECT util.derived_cols_populate(''"TNRS".taxon_match'');
669 14361 aaronmk
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
670 13577 aaronmk
$ make schemas/remake
671
672 14413 aaronmk
to remove a derived column:
673
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''col''));
674 14365 aaronmk
$ make schemas/remake
675
676 14413 aaronmk
to remove a non-derived column:
677
SELECT util.drop_column((''"TNRS".taxon_match'', ''col''));
678
$ make schemas/remake
679
680 14365 aaronmk
to move a derived column to the middle or to add a non-derived column:
681 13577 aaronmk
make the changes in inputs/.TNRS/schema.sql
682 14368 aaronmk
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS; runtime: 1 min ("1m2.629s")
683 14313 aaronmk
SELECT util.derived_cols_update(''"TNRS".taxon_match'');
684 14317 aaronmk
SELECT util.derived_cols_repopulate(''"TNRS".taxon_match'');
685 14361 aaronmk
SELECT util.recreate_view(''"TNRS".taxon_best_match'');
686 13577 aaronmk
$ make schemas/remake
687 13582 aaronmk
688 13584 aaronmk
to add a constraint: runtime: 3 min ("173620 ms")
689 13575 aaronmk
';
690 10778 aaronmk
691
692
--
693 14311 aaronmk
-- Name: COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
694
--
695
696
COMMENT ON COLUMN taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org" IS '
697
= "*Unmatched_terms"
698
699
derived column
700
701
to modify expr:
702
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org'')::util.col, $$"*Unmatched_terms"$$)::util.derived_col_def);
703
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
704
705
to rename:
706
# rename column
707
# rename CHECK constraint
708
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
709 14379 aaronmk
710
to drop:
711
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org'')::util.col);
712
	-- DROP __ CASCADE doesn''t work when there are dependent views
713 14311 aaronmk
';
714
715
716
--
717 14279 aaronmk
-- Name: COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
718 14254 aaronmk
--
719
720 14279 aaronmk
COMMENT ON COLUMN taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
721 14283 aaronmk
= ("*Genus_matched" || '' ''::text) || "*Specific_epithet_matched"
722 14254 aaronmk
723 14283 aaronmk
derived column
724
725 14275 aaronmk
to modify expr:
726 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$("*Genus_matched" || '' ''::text) || "*Specific_epithet_matched"$$)::util.derived_col_def);
727 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
728 14275 aaronmk
729
to rename:
730
# rename column
731
# rename CHECK constraint
732
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
733 14379 aaronmk
734
to drop:
735
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
736
	-- DROP __ CASCADE doesn''t work when there are dependent views
737 14254 aaronmk
';
738
739
740
--
741 14329 aaronmk
-- Name: COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
742
--
743
744
COMMENT ON COLUMN taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org" IS '
745
= NULLIF("*Name_matched", ''No suitable matches found.''::text)
746
747
derived column
748
749
to modify expr:
750
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched~Name[_no_author]___@TNRS__@vegpath.org'')::util.col, $$NULLIF("*Name_matched", ''No suitable matches found.''::text)$$)::util.derived_col_def);
751
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
752
753
to rename:
754
# rename column
755
# rename CHECK constraint
756
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
757 14379 aaronmk
758
to drop:
759
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''matched~Name[_no_author]___@TNRS__@vegpath.org'')::util.col);
760
	-- DROP __ CASCADE doesn''t work when there are dependent views
761 14329 aaronmk
';
762
763
764
--
765 14279 aaronmk
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
766 14257 aaronmk
--
767
768 14279 aaronmk
COMMENT ON COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
769 14330 aaronmk
= "matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)
770 14257 aaronmk
771 14283 aaronmk
derived column
772
773 14275 aaronmk
to modify expr:
774 14330 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"matched~Name[_no_author]___@TNRS__@vegpath.org" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)$$)::util.derived_col_def);
775 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
776 14275 aaronmk
777
to rename:
778
# rename column
779
# rename CHECK constraint
780
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
781 14379 aaronmk
782
to drop:
783
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
784
	-- DROP __ CASCADE doesn''t work when there are dependent views
785 14257 aaronmk
';
786
787
788
--
789 14279 aaronmk
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
790 14257 aaronmk
--
791
792 14279 aaronmk
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
793 14283 aaronmk
= "*Accepted_name" IS NOT NULL
794 14257 aaronmk
795 14283 aaronmk
derived column
796
797 14275 aaronmk
to modify expr:
798 14279 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
799 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
800 14275 aaronmk
801
to rename:
802
# rename column
803
# rename CHECK constraint
804
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
805 14379 aaronmk
806
to drop:
807
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col);
808
	-- DROP __ CASCADE doesn''t work when there are dependent views
809 14257 aaronmk
';
810
811
812
--
813 14318 aaronmk
-- Name: COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
814
--
815
816
COMMENT ON COLUMN taxon_match."Accepted_family__@TNRS__@vegpath.org" IS '
817
= COALESCE("*Accepted_name_family",
818
CASE
819
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
820
    ELSE NULL::text
821
END)
822
823
derived column
824
825
to modify expr:
826
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col, $$COALESCE("*Accepted_name_family",
827
CASE
828
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN "*Accepted_name"
829
    ELSE NULL::text
830
END)$$)::util.derived_col_def);
831
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
832
833
to rename:
834
# rename column
835
# rename CHECK constraint
836
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
837 14379 aaronmk
838
to drop:
839
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''Accepted_family__@TNRS__@vegpath.org'')::util.col);
840
	-- DROP __ CASCADE doesn''t work when there are dependent views
841 14318 aaronmk
';
842
843
844
--
845 14366 aaronmk
-- Name: COLUMN taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
846
--
847
848
COMMENT ON COLUMN taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org" IS '
849
= rtrim("*Accepted_name_species", '' ''::text)
850
851
derived column
852
853
to modify expr:
854
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''Accepted_species[_binomial]__@TNRS__@vegpath.org'')::util.col, $$rtrim("*Accepted_name_species", '' ''::text)$$)::util.derived_col_def);
855
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
856
857
to rename:
858
# rename column
859
# rename CHECK constraint
860
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
861 14379 aaronmk
862
to drop:
863
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''Accepted_species[_binomial]__@TNRS__@vegpath.org'')::util.col);
864
	-- DROP __ CASCADE doesn''t work when there are dependent views
865 14366 aaronmk
';
866
867
868
--
869 14376 aaronmk
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}"; Type: COMMENT; Schema: TNRS; Owner: -
870 14264 aaronmk
--
871
872 14376 aaronmk
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}" IS '
873 14375 aaronmk
= regexp_split_to_array("*Accepted_name", '' ''::text)
874 14264 aaronmk
875 14283 aaronmk
derived column
876
877 14275 aaronmk
to modify expr:
878 14376 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet,infra_{rank,epithet}}'')::util.col, $$regexp_split_to_array("*Accepted_name", '' ''::text)$$)::util.derived_col_def);
879 14264 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
880 14275 aaronmk
881
to rename:
882
# rename column
883
# rename CHECK constraint
884
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
885 14379 aaronmk
886
to drop:
887
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet,infra_{rank,epithet}}'')::util.col);
888
	-- DROP __ CASCADE doesn''t work when there are dependent views
889 14264 aaronmk
';
890
891
892
--
893 14279 aaronmk
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
894 14265 aaronmk
--
895
896 14279 aaronmk
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
897 14377 aaronmk
= "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]
898 14265 aaronmk
899 14283 aaronmk
derived column
900
901 14275 aaronmk
to modify expr:
902 14377 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[1]$$)::util.derived_col_def);
903 14265 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
904 14275 aaronmk
905
to rename:
906
# rename column
907
# rename CHECK constraint
908
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
909 14379 aaronmk
910
to drop:
911
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col);
912
	-- DROP __ CASCADE doesn''t work when there are dependent views
913 14265 aaronmk
';
914
915
916
--
917 14279 aaronmk
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
918 14266 aaronmk
--
919
920 14279 aaronmk
COMMENT ON COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org" IS '
921 14376 aaronmk
= "__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]
922 14266 aaronmk
923 14283 aaronmk
derived column
924
925 14275 aaronmk
to modify expr:
926 14376 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[2]$$)::util.derived_col_def);
927 14266 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
928 14275 aaronmk
929
to rename:
930
# rename column
931
# rename CHECK constraint
932
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
933 14379 aaronmk
934
to drop:
935
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col);
936
	-- DROP __ CASCADE doesn''t work when there are dependent views
937 14266 aaronmk
';
938
939
940
--
941 14311 aaronmk
-- Name: COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
942
--
943
944
COMMENT ON COLUMN taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
945
= CASE
946 14323 aaronmk
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
947 14327 aaronmk
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
948 14367 aaronmk
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
949 14311 aaronmk
END
950
951
derived column
952
953
to modify expr:
954
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
955 14323 aaronmk
    WHEN ("*Accepted_name_rank" = ''family''::text) THEN concat_ws('' ''::text, "Accepted_family__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
956 14327 aaronmk
    WHEN ("*Accepted_name_rank" = ''genus''::text) THEN concat_ws('' ''::text, "[accepted_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
957 14367 aaronmk
    ELSE "Accepted_species[_binomial]__@TNRS__@vegpath.org"
958 14311 aaronmk
END$$)::util.derived_col_def);
959
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
960
961
to rename:
962
# rename column
963
# rename CHECK constraint
964
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
965 14379 aaronmk
966
to drop:
967
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col);
968
	-- DROP __ CASCADE doesn''t work when there are dependent views
969 14311 aaronmk
';
970
971
972
--
973 14279 aaronmk
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
974 14267 aaronmk
--
975
976 14279 aaronmk
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
977 14378 aaronmk
= NULLIF("__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[3:4], ''{}''::text[])
978 14267 aaronmk
979 14283 aaronmk
derived column
980
981 14275 aaronmk
to modify expr:
982 14378 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col, $$NULLIF("__accepted_{genus,specific_epithet,infra_{rank,epithet}}"[3:4], ''{}''::text[])$$)::util.derived_col_def);
983 14267 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
984 14275 aaronmk
985
to rename:
986
# rename column
987
# rename CHECK constraint
988
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
989 14379 aaronmk
990
to drop:
991
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col);
992
	-- DROP __ CASCADE doesn''t work when there are dependent views
993 14267 aaronmk
';
994
995
996
--
997 14279 aaronmk
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
998 14267 aaronmk
--
999
1000 14279 aaronmk
COMMENT ON COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1001 14283 aaronmk
= "__accepted_infraspecific_{rank,epithet}"[1]
1002 14267 aaronmk
1003 14283 aaronmk
derived column
1004
1005 14275 aaronmk
to modify expr:
1006 14279 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$"__accepted_infraspecific_{rank,epithet}"[1]$$)::util.derived_col_def);
1007 14267 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1008 14275 aaronmk
1009
to rename:
1010
# rename column
1011
# rename CHECK constraint
1012
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1013 14379 aaronmk
1014
to drop:
1015
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col);
1016
	-- DROP __ CASCADE doesn''t work when there are dependent views
1017 14267 aaronmk
';
1018
1019
1020
--
1021 14279 aaronmk
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1022 14269 aaronmk
--
1023
1024 14279 aaronmk
COMMENT ON COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1025 14283 aaronmk
= "__accepted_infraspecific_{rank,epithet}"[2]
1026 14269 aaronmk
1027 14283 aaronmk
derived column
1028
1029 14275 aaronmk
to modify expr:
1030 14279 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_infraspecific_{rank,epithet}"[2]$$)::util.derived_col_def);
1031 14269 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1032 14275 aaronmk
1033
to rename:
1034
# rename column
1035
# rename CHECK constraint
1036
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1037 14379 aaronmk
1038
to drop:
1039
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col);
1040
	-- DROP __ CASCADE doesn''t work when there are dependent views
1041 14269 aaronmk
';
1042
1043
1044
--
1045 14279 aaronmk
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1046 14278 aaronmk
--
1047
1048 14279 aaronmk
COMMENT ON COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1049 14283 aaronmk
= "*Accepted_name" || COALESCE(('' ''::text || "*Accepted_name_author"), ''''::text)
1050 14278 aaronmk
1051 14283 aaronmk
derived column
1052
1053 14278 aaronmk
to modify expr:
1054 14279 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"*Accepted_name" || COALESCE(('' ''::text || "*Accepted_name_author"), ''''::text)$$)::util.derived_col_def);
1055 14278 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1056
1057
to rename:
1058
# rename column
1059
# rename CHECK constraint
1060
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1061 14379 aaronmk
1062
to drop:
1063
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[accepted_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
1064
	-- DROP __ CASCADE doesn''t work when there are dependent views
1065 14278 aaronmk
';
1066
1067
1068
--
1069 14328 aaronmk
-- Name: COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1070
--
1071
1072
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org" IS '
1073
= "TNRS".map_taxonomic_status("*Taxonomic_status", "*Accepted_name")
1074
1075
derived column
1076
1077
to modify expr:
1078
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonomicStatus__@DwC__@vegpath.org'')::util.col, $$"TNRS".map_taxonomic_status("*Taxonomic_status", "*Accepted_name")$$)::util.derived_col_def);
1079
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1080
1081
to rename:
1082
# rename column
1083
# rename CHECK constraint
1084
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1085 14379 aaronmk
1086
to drop:
1087
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]taxonomicStatus__@DwC__@vegpath.org'')::util.col);
1088
	-- DROP __ CASCADE doesn''t work when there are dependent views
1089 14328 aaronmk
';
1090
1091
1092
--
1093 14281 aaronmk
-- Name: COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1094
--
1095
1096
COMMENT ON COLUMN taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org" IS '
1097 14283 aaronmk
= CASE
1098 14282 aaronmk
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
1099
    ELSE "*Name_matched_rank"
1100
END
1101 14281 aaronmk
1102 14283 aaronmk
derived column
1103
1104 14281 aaronmk
to modify expr:
1105 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col, $$CASE
1106
    WHEN matched_has_accepted THEN "*Accepted_name_rank"
1107
    ELSE "*Name_matched_rank"
1108
END$$)::util.derived_col_def);
1109 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1110
1111
to rename:
1112
# rename column
1113
# rename CHECK constraint
1114
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1115 14379 aaronmk
1116
to drop:
1117
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]taxonRank__@DwC__@vegpath.org'')::util.col);
1118
	-- DROP __ CASCADE doesn''t work when there are dependent views
1119 14281 aaronmk
';
1120
1121
1122
--
1123
-- Name: COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1124
--
1125
1126
COMMENT ON COLUMN taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1127 14283 aaronmk
= CASE
1128 14323 aaronmk
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
1129 14282 aaronmk
    ELSE "*Name_matched_accepted_family"
1130
END
1131 14281 aaronmk
1132 14283 aaronmk
derived column
1133
1134 14281 aaronmk
to modify expr:
1135 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1136 14323 aaronmk
    WHEN matched_has_accepted THEN "Accepted_family__@TNRS__@vegpath.org"
1137 14282 aaronmk
    ELSE "*Name_matched_accepted_family"
1138
END$$)::util.derived_col_def);
1139 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1140
1141
to rename:
1142
# rename column
1143
# rename CHECK constraint
1144
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1145 14379 aaronmk
1146
to drop:
1147
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1148
	-- DROP __ CASCADE doesn''t work when there are dependent views
1149 14281 aaronmk
';
1150
1151
1152
--
1153
-- Name: COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1154
--
1155
1156
COMMENT ON COLUMN taxon_match."[scrubbed_]genus__@DwC__@vegpath.org" IS '
1157 14283 aaronmk
= CASE
1158 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1159
    ELSE "*Genus_matched"
1160
END
1161 14281 aaronmk
1162 14283 aaronmk
derived column
1163
1164 14281 aaronmk
to modify expr:
1165 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col, $$CASE
1166
    WHEN matched_has_accepted THEN "[accepted_]genus__@DwC__@vegpath.org"
1167
    ELSE "*Genus_matched"
1168
END$$)::util.derived_col_def);
1169 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1170
1171
to rename:
1172
# rename column
1173
# rename CHECK constraint
1174
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1175 14379 aaronmk
1176
to drop:
1177
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]genus__@DwC__@vegpath.org'')::util.col);
1178
	-- DROP __ CASCADE doesn''t work when there are dependent views
1179 14281 aaronmk
';
1180
1181
1182
--
1183
-- Name: COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1184
--
1185
1186
COMMENT ON COLUMN taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org" IS '
1187 14283 aaronmk
= CASE
1188 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1189
    ELSE "*Specific_epithet_matched"
1190
END
1191 14281 aaronmk
1192 14283 aaronmk
derived column
1193
1194 14281 aaronmk
to modify expr:
1195 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1196
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1197
    ELSE "*Specific_epithet_matched"
1198
END$$)::util.derived_col_def);
1199 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1200
1201
to rename:
1202
# rename column
1203
# rename CHECK constraint
1204
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1205 14379 aaronmk
1206
to drop:
1207
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]specificEpithet__@DwC__@vegpath.org'')::util.col);
1208
	-- DROP __ CASCADE doesn''t work when there are dependent views
1209 14281 aaronmk
';
1210
1211
1212
--
1213
-- Name: COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1214
--
1215
1216
COMMENT ON COLUMN taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1217 14283 aaronmk
= CASE
1218 14367 aaronmk
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1219 14282 aaronmk
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1220
END
1221 14281 aaronmk
1222 14283 aaronmk
derived column
1223
1224 14281 aaronmk
to modify expr:
1225 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1226 14367 aaronmk
    WHEN matched_has_accepted THEN "Accepted_species[_binomial]__@TNRS__@vegpath.org"
1227 14282 aaronmk
    ELSE "[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org"
1228
END$$)::util.derived_col_def);
1229 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1230
1231
to rename:
1232
# rename column
1233
# rename CHECK constraint
1234
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1235 14379 aaronmk
1236
to drop:
1237
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1238
	-- DROP __ CASCADE doesn''t work when there are dependent views
1239 14281 aaronmk
';
1240
1241
1242
--
1243 14328 aaronmk
-- Name: COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1244
--
1245
1246
COMMENT ON COLUMN taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org" IS '
1247
= CASE
1248
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''family''::text) THEN concat_ws('' ''::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1249
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1250
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1251
END
1252
1253
derived column
1254
1255
to modify expr:
1256
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col, $$CASE
1257
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''family''::text) THEN concat_ws('' ''::text, "[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1258
    WHEN ("[scrubbed_]taxonRank__@DwC__@vegpath.org" = ''genus''::text) THEN concat_ws('' ''::text, "[scrubbed_]genus__@DwC__@vegpath.org", "[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org")
1259
    ELSE "[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org"
1260
END$$)::util.derived_col_def);
1261
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1262
1263
to rename:
1264
# rename column
1265
# rename CHECK constraint
1266
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1267 14379 aaronmk
1268
to drop:
1269
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org'')::util.col);
1270
	-- DROP __ CASCADE doesn''t work when there are dependent views
1271 14328 aaronmk
';
1272
1273
1274
--
1275 14281 aaronmk
-- Name: COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1276
--
1277
1278
COMMENT ON COLUMN taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
1279 14283 aaronmk
= CASE
1280 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1281
    ELSE "*Infraspecific_rank"
1282
END
1283 14281 aaronmk
1284 14283 aaronmk
derived column
1285
1286 14281 aaronmk
to modify expr:
1287 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col, $$CASE
1288
    WHEN matched_has_accepted THEN "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"
1289
    ELSE "*Infraspecific_rank"
1290
END$$)::util.derived_col_def);
1291 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1292
1293
to rename:
1294
# rename column
1295
# rename CHECK constraint
1296
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1297 14379 aaronmk
1298
to drop:
1299
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org'')::util.col);
1300
	-- DROP __ CASCADE doesn''t work when there are dependent views
1301 14281 aaronmk
';
1302
1303
1304
--
1305
-- Name: COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1306
--
1307
1308
COMMENT ON COLUMN taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org" IS '
1309 14283 aaronmk
= CASE
1310 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1311
    ELSE "*Infraspecific_epithet_matched"
1312
END
1313 14281 aaronmk
1314 14283 aaronmk
derived column
1315
1316 14281 aaronmk
to modify expr:
1317 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$CASE
1318
    WHEN matched_has_accepted THEN "[accepted_]specificEpithet__@DwC__@vegpath.org"
1319
    ELSE "*Infraspecific_epithet_matched"
1320
END$$)::util.derived_col_def);
1321 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1322
1323
to rename:
1324
# rename column
1325
# rename CHECK constraint
1326
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1327 14379 aaronmk
1328
to drop:
1329
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col);
1330
	-- DROP __ CASCADE doesn''t work when there are dependent views
1331 14281 aaronmk
';
1332
1333
1334
--
1335
-- Name: COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1336
--
1337
1338
COMMENT ON COLUMN taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1339 14283 aaronmk
= CASE
1340 14282 aaronmk
    WHEN matched_has_accepted THEN "*Accepted_name"
1341 14330 aaronmk
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1342 14282 aaronmk
END
1343 14281 aaronmk
1344 14283 aaronmk
derived column
1345
1346 14281 aaronmk
to modify expr:
1347 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1348
    WHEN matched_has_accepted THEN "*Accepted_name"
1349 14330 aaronmk
    ELSE "matched~Name[_no_author]___@TNRS__@vegpath.org"
1350 14282 aaronmk
END$$)::util.derived_col_def);
1351 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1352
1353
to rename:
1354
# rename column
1355
# rename CHECK constraint
1356
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1357 14379 aaronmk
1358
to drop:
1359
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1360
	-- DROP __ CASCADE doesn''t work when there are dependent views
1361 14281 aaronmk
';
1362
1363
1364
--
1365
-- Name: COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1366
--
1367
1368
COMMENT ON COLUMN taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org" IS '
1369 14283 aaronmk
= CASE
1370 14282 aaronmk
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1371
    ELSE "*Name_matched_author"
1372
END
1373 14281 aaronmk
1374 14283 aaronmk
derived column
1375
1376 14281 aaronmk
to modify expr:
1377 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col, $$CASE
1378
    WHEN matched_has_accepted THEN "*Accepted_name_author"
1379
    ELSE "*Name_matched_author"
1380
END$$)::util.derived_col_def);
1381 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1382
1383
to rename:
1384
# rename column
1385
# rename CHECK constraint
1386
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1387 14379 aaronmk
1388
to drop:
1389
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org'')::util.col);
1390
	-- DROP __ CASCADE doesn''t work when there are dependent views
1391 14281 aaronmk
';
1392
1393
1394
--
1395
-- Name: COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
1396
--
1397
1398
COMMENT ON COLUMN taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
1399 14283 aaronmk
= CASE
1400 14282 aaronmk
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1401
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1402
END
1403 14281 aaronmk
1404 14283 aaronmk
derived column
1405
1406 14281 aaronmk
to modify expr:
1407 14282 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$CASE
1408
    WHEN matched_has_accepted THEN "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
1409
    ELSE "[matched_]scientificName[_with_author]__@DwC__@vegpath.org"
1410
END$$)::util.derived_col_def);
1411 14281 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
1412
1413
to rename:
1414
# rename column
1415
# rename CHECK constraint
1416
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
1417 14379 aaronmk
1418
to drop:
1419
SELECT util.drop_derived_col((''"TNRS".taxon_match'', ''[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col);
1420
	-- DROP __ CASCADE doesn''t work when there are dependent views
1421 14281 aaronmk
';
1422
1423
1424
--
1425 13878 aaronmk
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
1426
--
1427
1428
CREATE VIEW taxon_best_match AS
1429
 SELECT taxon_match.batch,
1430
    taxon_match.match_num,
1431 14111 aaronmk
    taxon_match."*Name_number",
1432
    taxon_match."*Name_submitted",
1433
    taxon_match."*Overall_score",
1434
    taxon_match."*Name_matched",
1435
    taxon_match."*Name_matched_rank",
1436
    taxon_match."*Name_score",
1437
    taxon_match."*Name_matched_author",
1438
    taxon_match."*Name_matched_url",
1439
    taxon_match."*Author_matched",
1440
    taxon_match."*Author_score",
1441
    taxon_match."*Family_matched",
1442
    taxon_match."*Family_score",
1443
    taxon_match."*Name_matched_accepted_family",
1444
    taxon_match."*Genus_matched",
1445
    taxon_match."*Genus_score",
1446
    taxon_match."*Specific_epithet_matched",
1447
    taxon_match."*Specific_epithet_score",
1448
    taxon_match."*Infraspecific_rank",
1449
    taxon_match."*Infraspecific_epithet_matched",
1450
    taxon_match."*Infraspecific_epithet_score",
1451
    taxon_match."*Infraspecific_rank_2",
1452
    taxon_match."*Infraspecific_epithet_2_matched",
1453
    taxon_match."*Infraspecific_epithet_2_score",
1454
    taxon_match."*Annotations",
1455
    taxon_match."*Unmatched_terms",
1456
    taxon_match."*Taxonomic_status",
1457
    taxon_match."*Accepted_name",
1458
    taxon_match."*Accepted_name_author",
1459
    taxon_match."*Accepted_name_rank",
1460
    taxon_match."*Accepted_name_url",
1461
    taxon_match."*Accepted_name_species",
1462
    taxon_match."*Accepted_name_family",
1463
    taxon_match."*Selected",
1464
    taxon_match."*Source",
1465
    taxon_match."*Warnings",
1466
    taxon_match."*Accepted_name_lsid",
1467 13878 aaronmk
    taxon_match.is_valid_match,
1468 14268 aaronmk
    taxon_match.scrubbed_unique_taxon_name,
1469 14359 aaronmk
    taxon_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1470 14284 aaronmk
    taxon_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1471 14359 aaronmk
    taxon_match."matched~Name[_no_author]___@TNRS__@vegpath.org",
1472 14284 aaronmk
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1473
    taxon_match.matched_has_accepted,
1474 14359 aaronmk
    taxon_match."Accepted_family__@TNRS__@vegpath.org",
1475 14366 aaronmk
    taxon_match."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1476 14388 aaronmk
    taxon_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}",
1477 14268 aaronmk
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
1478
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1479 14359 aaronmk
    taxon_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1480 14268 aaronmk
    taxon_match."__accepted_infraspecific_{rank,epithet}",
1481
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1482
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1483 14284 aaronmk
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1484 14359 aaronmk
    taxon_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1485 14284 aaronmk
    taxon_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1486
    taxon_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1487
    taxon_match."[scrubbed_]genus__@DwC__@vegpath.org",
1488
    taxon_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1489
    taxon_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1490 14359 aaronmk
    taxon_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1491 14284 aaronmk
    taxon_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1492
    taxon_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1493
    taxon_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1494
    taxon_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1495
    taxon_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1496 13878 aaronmk
   FROM taxon_match
1497 14111 aaronmk
  WHERE (taxon_match."*Selected" = 'true'::text);
1498 13878 aaronmk
1499
1500
--
1501
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
1502
--
1503
1504
COMMENT ON VIEW taxon_best_match IS '
1505
to modify:
1506
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
1507
SELECT __
1508
$$);
1509
';
1510
1511
1512
--
1513 13866 aaronmk
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
1514
--
1515
1516
CREATE VIEW taxon_match_input AS
1517 14111 aaronmk
 SELECT taxon_match."*Name_number" AS "Name_number",
1518
    taxon_match."*Name_submitted" AS "Name_submitted",
1519
    taxon_match."*Overall_score" AS "Overall_score",
1520
    taxon_match."*Name_matched" AS "Name_matched",
1521
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
1522
    taxon_match."*Name_score" AS "Name_score",
1523
    taxon_match."*Name_matched_author" AS "Name_matched_author",
1524
    taxon_match."*Name_matched_url" AS "Name_matched_url",
1525
    taxon_match."*Author_matched" AS "Author_matched",
1526
    taxon_match."*Author_score" AS "Author_score",
1527
    taxon_match."*Family_matched" AS "Family_matched",
1528
    taxon_match."*Family_score" AS "Family_score",
1529
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
1530
    taxon_match."*Genus_matched" AS "Genus_matched",
1531
    taxon_match."*Genus_score" AS "Genus_score",
1532
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
1533
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
1534
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
1535
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
1536
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
1537
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
1538
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
1539
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
1540
    taxon_match."*Annotations" AS "Annotations",
1541
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
1542
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
1543
    taxon_match."*Accepted_name" AS "Accepted_name",
1544
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
1545
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
1546
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
1547
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
1548
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
1549
    taxon_match."*Selected" AS "Selected",
1550
    taxon_match."*Source" AS "Source",
1551
    taxon_match."*Warnings" AS "Warnings",
1552
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
1553 13866 aaronmk
   FROM taxon_match;
1554
1555
1556
--
1557
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
1558
--
1559
1560
CREATE TABLE taxon_match_input__copy_to (
1561
    "Name_number" integer,
1562
    "Name_submitted" text,
1563
    "Overall_score" double precision,
1564
    "Name_matched" text,
1565
    "Name_matched_rank" text,
1566
    "Name_score" double precision,
1567
    "Name_matched_author" text,
1568
    "Name_matched_url" text,
1569
    "Author_matched" text,
1570
    "Author_score" double precision,
1571
    "Family_matched" text,
1572
    "Family_score" double precision,
1573
    "Name_matched_accepted_family" text,
1574
    "Genus_matched" text,
1575
    "Genus_score" double precision,
1576
    "Specific_epithet_matched" text,
1577
    "Specific_epithet_score" double precision,
1578
    "Infraspecific_rank" text,
1579
    "Infraspecific_epithet_matched" text,
1580
    "Infraspecific_epithet_score" double precision,
1581
    "Infraspecific_rank_2" text,
1582
    "Infraspecific_epithet_2_matched" text,
1583
    "Infraspecific_epithet_2_score" double precision,
1584
    "Annotations" text,
1585
    "Unmatched_terms" text,
1586
    "Taxonomic_status" text,
1587
    "Accepted_name" text,
1588
    "Accepted_name_author" text,
1589
    "Accepted_name_rank" text,
1590
    "Accepted_name_url" text,
1591
    "Accepted_name_species" text,
1592
    "Accepted_name_family" text,
1593
    "Selected" text,
1594
    "Source" text,
1595
    "Warnings" text,
1596
    "Accepted_name_lsid" text
1597
);
1598
1599
1600
--
1601 11964 aaronmk
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1602
--
1603
1604
CREATE VIEW taxon_scrub AS
1605 14434 aaronmk
 SELECT taxon_best_match.batch,
1606
    taxon_best_match.match_num,
1607
    taxon_best_match."*Name_number",
1608
    taxon_best_match."*Name_submitted",
1609
    taxon_best_match."*Overall_score",
1610
    taxon_best_match."*Name_matched",
1611
    taxon_best_match."*Name_matched_rank",
1612
    taxon_best_match."*Name_score",
1613
    taxon_best_match."*Name_matched_author",
1614
    taxon_best_match."*Name_matched_url",
1615
    taxon_best_match."*Author_matched",
1616
    taxon_best_match."*Author_score",
1617
    taxon_best_match."*Family_matched",
1618
    taxon_best_match."*Family_score",
1619
    taxon_best_match."*Name_matched_accepted_family",
1620
    taxon_best_match."*Genus_matched",
1621
    taxon_best_match."*Genus_score",
1622
    taxon_best_match."*Specific_epithet_matched",
1623
    taxon_best_match."*Specific_epithet_score",
1624
    taxon_best_match."*Infraspecific_rank",
1625
    taxon_best_match."*Infraspecific_epithet_matched",
1626
    taxon_best_match."*Infraspecific_epithet_score",
1627
    taxon_best_match."*Infraspecific_rank_2",
1628
    taxon_best_match."*Infraspecific_epithet_2_matched",
1629
    taxon_best_match."*Infraspecific_epithet_2_score",
1630
    taxon_best_match."*Annotations",
1631
    taxon_best_match."*Unmatched_terms",
1632
    taxon_best_match."*Taxonomic_status",
1633
    taxon_best_match."*Accepted_name",
1634
    taxon_best_match."*Accepted_name_author",
1635
    taxon_best_match."*Accepted_name_rank",
1636
    taxon_best_match."*Accepted_name_url",
1637
    taxon_best_match."*Accepted_name_species",
1638
    taxon_best_match."*Accepted_name_family",
1639
    taxon_best_match."*Selected",
1640
    taxon_best_match."*Source",
1641
    taxon_best_match."*Warnings",
1642
    taxon_best_match."*Accepted_name_lsid",
1643
    taxon_best_match.is_valid_match,
1644
    taxon_best_match.scrubbed_unique_taxon_name,
1645
    taxon_best_match."[parsed_]morphospecies[_suffix]__@Brad__.morphosp@vegpath.org",
1646
    taxon_best_match."[matched_]species[_binomial]~(-Accepted_-)__@TNRS__@vegpath.org",
1647
    taxon_best_match."matched~Name[_no_author]___@TNRS__@vegpath.org",
1648
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1649
    taxon_best_match.matched_has_accepted,
1650
    taxon_best_match."Accepted_family__@TNRS__@vegpath.org",
1651
    taxon_best_match."Accepted_species[_binomial]__@TNRS__@vegpath.org",
1652
    taxon_best_match."__accepted_{genus,specific_epithet,infra_{rank,epithet}}",
1653
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
1654
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
1655
    taxon_best_match."[accepted_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1656
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
1657
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1658
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1659
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1660
    taxon_best_match."[scrubbed_]taxonomicStatus__@DwC__@vegpath.org",
1661
    taxon_best_match."[scrubbed_]taxonRank__@DwC__@vegpath.org",
1662
    taxon_best_match."[scrubbed_]family~(-Accepted_-)__@TNRS__@vegpath.org",
1663
    taxon_best_match."[scrubbed_]genus__@DwC__@vegpath.org",
1664
    taxon_best_match."[scrubbed_]specificEpithet__@DwC__@vegpath.org",
1665
    taxon_best_match."[scrubbed_]species[_binom]~(-Accepted_-)__@TNRS__@vegpath.org",
1666
    taxon_best_match."[scrubbed_]morphospecies[_binomial]__@Brad__.TNRS@vegpath.org",
1667
    taxon_best_match."[scrubbed_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1668
    taxon_best_match."[scrubbed_]infraspecificEpithet__@DwC__@vegpath.org",
1669
    taxon_best_match."[scrubbed_]name[_no_author]~(-Accepted_-)__@TNRS__@vegpath.org",
1670
    taxon_best_match."[scrubbed_]author~(-Accepted_-)__@TNRS__@vegpath.org",
1671
    taxon_best_match."[scrubbed_]scientificName[_with_author]__@DwC__@vegpath.org"
1672
   FROM taxon_best_match
1673
  WHERE taxon_best_match.is_valid_match;
1674 11964 aaronmk
1675
1676
--
1677
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1678
--
1679
1680 13443 aaronmk
COMMENT ON VIEW taxon_scrub IS '
1681 13531 aaronmk
to modify:
1682 13845 aaronmk
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1683 13647 aaronmk
SELECT __
1684 13531 aaronmk
$$);
1685 14432 aaronmk
1686
to merge synonymous columns:
1687
# temporarily move correct col out of the way, to allow renaming synonym col:
1688
ALTER TABLE "TNRS".taxon_scrub RENAME "correct_col" TO "_correct_col";
1689
## also perform the rename in any dependent .* views (currently there are none)
1690
# rename columns to replace:
1691
ALTER TABLE "TNRS".taxon_scrub RENAME "synonym_col" TO "correct_col";
1692
## also perform the rename in any dependent .* views (currently there are none)
1693
# remove duplicate cols and now-unnecessary CASE wrappers
1694
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1695
SELECT __ -- with the CASE-wrapped synonym col removed
1696
$$);
1697 13443 aaronmk
';
1698 11964 aaronmk
1699
1700
--
1701 10778 aaronmk
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1702
--
1703
1704
ALTER TABLE ONLY batch_download_settings
1705
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1706
1707
1708
--
1709
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1710
--
1711
1712
ALTER TABLE ONLY batch
1713
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1714
1715
1716
--
1717
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1718
--
1719
1720
ALTER TABLE ONLY batch
1721
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1722
1723
1724
--
1725
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1726
--
1727
1728
ALTER TABLE ONLY client_version
1729
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1730
1731
1732
--
1733 13868 aaronmk
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1734 10778 aaronmk
--
1735
1736 13861 aaronmk
ALTER TABLE ONLY taxon_match
1737 13868 aaronmk
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1738 10778 aaronmk
1739 14125 aaronmk
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1740 10778 aaronmk
1741 14125 aaronmk
1742 10778 aaronmk
--
1743 10793 aaronmk
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1744
--
1745
1746
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1747
1748
1749
--
1750 13879 aaronmk
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1751 13589 aaronmk
--
1752
1753 14111 aaronmk
CREATE INDEX taxon_best_match__valid_match ON taxon_match USING btree ("*Name_submitted") WHERE (("*Selected" = 'true'::text) AND is_valid_match);
1754 13589 aaronmk
1755
1756
--
1757 13879 aaronmk
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1758 13874 aaronmk
--
1759
1760 14111 aaronmk
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1761 13874 aaronmk
1762
1763
--
1764 13879 aaronmk
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1765 11607 aaronmk
--
1766
1767 14111 aaronmk
CREATE UNIQUE INDEX taxon_match__one_selected_match ON taxon_match USING btree (batch, "*Name_number") WHERE ("*Selected" = 'true'::text);
1768 11607 aaronmk
1769
1770
--
1771 10778 aaronmk
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1772
--
1773
1774
CREATE TRIGGER batch__fill BEFORE INSERT OR UPDATE ON batch FOR EACH ROW EXECUTE PROCEDURE batch__fill();
1775
1776
1777
--
1778 13868 aaronmk
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1779 13866 aaronmk
--
1780
1781 13868 aaronmk
CREATE TRIGGER taxon_match__batch_begin BEFORE INSERT ON taxon_match_input__copy_to FOR EACH STATEMENT EXECUTE PROCEDURE taxon_match__batch_begin();
1782 13866 aaronmk
1783
1784
--
1785 13868 aaronmk
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1786 13567 aaronmk
--
1787
1788 13868 aaronmk
CREATE TRIGGER taxon_match__fill BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill();
1789 13567 aaronmk
1790
1791
--
1792 14122 aaronmk
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1793
--
1794
1795
CREATE TRIGGER taxon_match__fill_derived BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill_derived();
1796
1797
1798
--
1799 13868 aaronmk
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1800 13578 aaronmk
--
1801
1802 13868 aaronmk
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1803 13578 aaronmk
1804
1805
--
1806 13868 aaronmk
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1807 10778 aaronmk
--
1808
1809 13868 aaronmk
CREATE TRIGGER taxon_match_input__copy_to__insert BEFORE INSERT ON taxon_match_input__copy_to FOR EACH ROW EXECUTE PROCEDURE taxon_match_input__copy_to__insert();
1810 10778 aaronmk
1811
1812
--
1813
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1814
--
1815
1816
ALTER TABLE ONLY batch
1817
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1818
1819
1820
--
1821
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1822
--
1823
1824
ALTER TABLE ONLY batch_download_settings
1825
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1826
1827
1828
--
1829 13868 aaronmk
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1830 10778 aaronmk
--
1831
1832 13861 aaronmk
ALTER TABLE ONLY taxon_match
1833 13868 aaronmk
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1834 10778 aaronmk
1835
1836
--
1837
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1838
--
1839
1840
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1841
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1842
GRANT ALL ON SCHEMA "TNRS" TO bien;
1843
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1844
1845
1846
--
1847 13861 aaronmk
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1848 10778 aaronmk
--
1849
1850 13861 aaronmk
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1851
REVOKE ALL ON TABLE taxon_match FROM bien;
1852
GRANT ALL ON TABLE taxon_match TO bien;
1853
GRANT SELECT ON TABLE taxon_match TO bien_read;
1854 10778 aaronmk
1855
1856
--
1857 13878 aaronmk
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1858
--
1859
1860
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1861
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1862
GRANT ALL ON TABLE taxon_best_match TO bien;
1863
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1864
1865
1866
--
1867 13866 aaronmk
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
1868
--
1869
1870
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1871
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1872
GRANT ALL ON TABLE taxon_match_input TO bien;
1873
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1874
1875
1876
--
1877 14423 aaronmk
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1878
--
1879
1880
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
1881
REVOKE ALL ON TABLE taxon_scrub FROM bien;
1882
GRANT ALL ON TABLE taxon_scrub TO bien;
1883
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
1884
1885
1886
--
1887 10778 aaronmk
-- PostgreSQL database dump complete
1888
--