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 13868 aaronmk
-- Name: taxon_match__batch_begin(); Type: FUNCTION; Schema: TNRS; Owner: -
97 13866 aaronmk
--
98
99 13868 aaronmk
CREATE FUNCTION taxon_match__batch_begin() RETURNS trigger
100 13866 aaronmk
    LANGUAGE plpgsql
101
    AS $$
102
BEGIN
103 13869 aaronmk
	PERFORM util.seq__reset('pg_temp.taxon_match__match_num__seq', 0);
104 13567 aaronmk
	RETURN NULL;
105
END;
106
$$;
107
108
109
--
110 13868 aaronmk
-- Name: taxon_match__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
111 13578 aaronmk
--
112
113 13868 aaronmk
CREATE FUNCTION taxon_match__fill() RETURNS trigger
114 13578 aaronmk
    LANGUAGE plpgsql
115
    AS $$
116 11643 aaronmk
BEGIN
117 13871 aaronmk
	DECLARE
118
		"Specific_epithet_is_plant" boolean :=
119 11628 aaronmk
			(CASE
120 14111 aaronmk
			WHEN   new."*Infraspecific_epithet_matched"	 IS NOT NULL
121
				OR new."*Infraspecific_epithet_2_matched" IS NOT NULL
122
				OR new."*Specific_epithet_score" >= 0.9 -- fuzzy match
123 13871 aaronmk
				THEN true
124
			ELSE NULL -- ambiguous
125
			END);
126 14111 aaronmk
		never_homonym boolean = COALESCE(new."*Author_score" >= 0.6, false);
127 13871 aaronmk
			-- author disambiguates
128
		family_is_homonym boolean = NOT never_homonym
129 14111 aaronmk
			AND "TNRS".family_is_homonym(new."*Family_matched");
130 13871 aaronmk
		genus_is_homonym  boolean = NOT never_homonym
131 14111 aaronmk
			AND "TNRS".genus_is_homonym(new."*Genus_matched");
132 13871 aaronmk
	BEGIN
133
		/* exclude homonyms because these are not valid matches (TNRS provides a
134
		name, but the name is not meaningful because it is not unambiguous) */
135 14111 aaronmk
		new.is_valid_match = new."*Taxonomic_status" != 'Invalid'
136 13871 aaronmk
			AND COALESCE(CASE
137 14111 aaronmk
			WHEN new."*Family_score" = 1 AND NOT family_is_homonym -- exact match
138 13871 aaronmk
				THEN true
139
			ELSE -- consider genus
140 11628 aaronmk
				(CASE
141 14111 aaronmk
				WHEN new."*Genus_score" =  1	   -- exact match
142 13871 aaronmk
					THEN
143
					(CASE
144
					WHEN NOT genus_is_homonym THEN true
145
					ELSE "Specific_epithet_is_plant"
146
					END)
147 14111 aaronmk
				WHEN new."*Genus_score" >= 0.85 -- fuzzy match
148 13871 aaronmk
					THEN "Specific_epithet_is_plant"
149
				ELSE NULL -- ambiguous
150 11628 aaronmk
				END)
151 13871 aaronmk
			END, false);
152
	END;
153 11628 aaronmk
154 13871 aaronmk
	DECLARE
155
		matched_taxon_name_with_author text = NULLIF(concat_ws(' '
156 14111 aaronmk
			, NULLIF(NULLIF(new."*Name_matched_accepted_family", 'Unknown'),
157
				new."*Name_matched")
158
			, NULLIF(new."*Name_matched", 'No suitable matches found.')
159
			, new."*Name_matched_author"
160 13871 aaronmk
			), '');
161
		accepted_taxon_name_with_author text = NULLIF(concat_ws(' '
162 14111 aaronmk
			, NULLIF(NULLIF(new."*Accepted_name_family", 'Unknown'),
163
				new."*Accepted_name")
164
			, new."*Accepted_name"
165
			, new."*Accepted_name_author"
166 13871 aaronmk
			), '');
167
	BEGIN
168
		new.scrubbed_unique_taxon_name = COALESCE(
169
			accepted_taxon_name_with_author, matched_taxon_name_with_author);
170
	END;
171
172 11628 aaronmk
	RETURN new;
173 7134 aaronmk
END;
174 10778 aaronmk
$$;
175
176
177
--
178 13868 aaronmk
-- Name: FUNCTION taxon_match__fill(); Type: COMMENT; Schema: TNRS; Owner: -
179 10778 aaronmk
--
180
181 13868 aaronmk
COMMENT ON FUNCTION taxon_match__fill() IS '
182 13575 aaronmk
IMPORTANT: when changing this function, you must regenerate the derived cols:
183 13861 aaronmk
UPDATE "TNRS".taxon_match SET "Name_submitted" = "Name_submitted"
184 11715 aaronmk
runtime: 30 min ("5564082 rows affected, 1918900 ms execution time")
185 13861 aaronmk
VACUUM ANALYZE "TNRS".taxon_match -- to remove previous rows
186 13575 aaronmk
runtime: 1.5 min ("92633 ms")
187
';
188 7134 aaronmk
189 7251 aaronmk
190 13631 aaronmk
--
191 14122 aaronmk
-- Name: taxon_match__fill_derived(); Type: FUNCTION; Schema: TNRS; Owner: -
192
--
193
194
CREATE FUNCTION taxon_match__fill_derived() RETURNS trigger
195
    LANGUAGE plpgsql
196
    AS $$
197
BEGIN
198
	new."__accepted_{genus,specific_epithet}" = (SELECT
199 14150 aaronmk
		regexp_split_to_array("*Accepted_name_species", ' '::text)
200 14122 aaronmk
		FROM (SELECT new.*) new);
201
202 14257 aaronmk
	new."[accepted_]genus__@DwC__@vegpath.org" = (SELECT
203
		"__accepted_{genus,specific_epithet}"[1]
204
		FROM (SELECT new.*) new);
205
206
	new."[accepted_]specificEpithet__@DwC__@vegpath.org" = (SELECT
207
		"__accepted_{genus,specific_epithet}"[2]
208
		FROM (SELECT new.*) new);
209
210 14264 aaronmk
	new.__accepted_infraspecific_label = (SELECT
211
		ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''::text), ' '::text)
212
		FROM (SELECT new.*) new);
213
214 14265 aaronmk
	new."__accepted_infraspecific_{rank,epithet}" = (SELECT
215
		regexp_split_to_array(__accepted_infraspecific_label, ' '::text)
216
		FROM (SELECT new.*) new);
217
218 14266 aaronmk
	new."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" = (SELECT
219
		"__accepted_infraspecific_{rank,epithet}"[1]
220
		FROM (SELECT new.*) new);
221
222
	new."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" = (SELECT
223
		"__accepted_infraspecific_{rank,epithet}"[2]
224
		FROM (SELECT new.*) new);
225
226 14267 aaronmk
	new."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT
227
		"*Name_matched" || COALESCE((' '::text || "*Name_matched_author"), ''::text)
228
		FROM (SELECT new.*) new);
229
230
	new."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" = (SELECT
231
		"*Accepted_name" || COALESCE((' '::text || "*Accepted_name_author"), ''::text)
232
		FROM (SELECT new.*) new);
233
234 14269 aaronmk
	new._matched_has_accepted = (SELECT
235
		"*Accepted_name" IS NOT NULL
236
		FROM (SELECT new.*) new);
237
238 14122 aaronmk
	RETURN new;
239
END;
240
$$;
241
242
243
--
244 14254 aaronmk
-- Name: FUNCTION taxon_match__fill_derived(); Type: COMMENT; Schema: TNRS; Owner: -
245
--
246
247
COMMENT ON FUNCTION taxon_match__fill_derived() IS '
248
autogenerated, do not edit
249
250
to regenerate:
251
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
252
';
253
254
255
--
256 13868 aaronmk
-- Name: taxon_match__match_num__fill(); Type: FUNCTION; Schema: TNRS; Owner: -
257
--
258
259
CREATE FUNCTION taxon_match__match_num__fill() RETURNS trigger
260
    LANGUAGE plpgsql
261
    AS $$
262
BEGIN
263
	IF new.match_num IS NULL THEN
264 13869 aaronmk
		new.match_num = "TNRS".taxon_match__match_num__next();
265 13868 aaronmk
	END IF;
266
	RETURN new;
267
END;
268
$$;
269
270
271
--
272 13869 aaronmk
-- Name: taxon_match__match_num__next(); Type: FUNCTION; Schema: TNRS; Owner: -
273
--
274
275
CREATE FUNCTION taxon_match__match_num__next() RETURNS bigint
276
    LANGUAGE sql
277
    AS $$
278
SELECT nextval('pg_temp.taxon_match__match_num__seq');
279
$$;
280
281
282
--
283 13868 aaronmk
-- Name: taxon_match_input__copy_to__insert(); Type: FUNCTION; Schema: TNRS; Owner: -
284
--
285
286
CREATE FUNCTION taxon_match_input__copy_to__insert() RETURNS trigger
287
    LANGUAGE plpgsql
288
    AS $$
289
BEGIN
290
	INSERT INTO "TNRS".taxon_match_input SELECT new.*;
291
	RETURN NULL;
292
END;
293
$$;
294
295
296
--
297
-- Name: taxon_name_is_safe(text); Type: FUNCTION; Schema: TNRS; Owner: -
298
--
299
300
CREATE FUNCTION taxon_name_is_safe(taxon_name text) RETURNS boolean
301
    LANGUAGE sql IMMUTABLE
302
    AS $_$
303
SELECT NOT ($1 = ANY("TNRS".unsafe_taxon_names()))
304
$_$;
305
306
307
--
308 13631 aaronmk
-- Name: unsafe_taxon_names(); Type: FUNCTION; Schema: TNRS; Owner: -
309
--
310
311
CREATE FUNCTION unsafe_taxon_names() RETURNS text[]
312
    LANGUAGE sql IMMUTABLE
313
    AS $$
314
SELECT ARRAY[
315 13686 aaronmk
]::text[]
316 13631 aaronmk
$$;
317
318
319 10778 aaronmk
SET default_tablespace = '';
320
321
SET default_with_oids = false;
322
323 10728 aaronmk
--
324 13861 aaronmk
-- Name: taxon_match; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
325 10778 aaronmk
--
326 7251 aaronmk
327 13861 aaronmk
CREATE TABLE taxon_match (
328 10778 aaronmk
    batch text DEFAULT now() NOT NULL,
329 13580 aaronmk
    match_num integer NOT NULL,
330 14111 aaronmk
    "*Name_number" integer NOT NULL,
331
    "*Name_submitted" text NOT NULL,
332
    "*Overall_score" double precision,
333
    "*Name_matched" text,
334
    "*Name_matched_rank" text,
335
    "*Name_score" double precision,
336
    "*Name_matched_author" text,
337
    "*Name_matched_url" text,
338
    "*Author_matched" text,
339
    "*Author_score" double precision,
340
    "*Family_matched" text,
341
    "*Family_score" double precision,
342
    "*Name_matched_accepted_family" text,
343
    "*Genus_matched" text,
344
    "*Genus_score" double precision,
345
    "*Specific_epithet_matched" text,
346
    "*Specific_epithet_score" double precision,
347
    "*Infraspecific_rank" text,
348
    "*Infraspecific_epithet_matched" text,
349
    "*Infraspecific_epithet_score" double precision,
350
    "*Infraspecific_rank_2" text,
351
    "*Infraspecific_epithet_2_matched" text,
352
    "*Infraspecific_epithet_2_score" double precision,
353
    "*Annotations" text,
354
    "*Unmatched_terms" text,
355
    "*Taxonomic_status" text,
356
    "*Accepted_name" text,
357
    "*Accepted_name_author" text,
358
    "*Accepted_name_rank" text,
359
    "*Accepted_name_url" text,
360
    "*Accepted_name_species" text,
361
    "*Accepted_name_family" text,
362
    "*Selected" text,
363
    "*Source" text,
364
    "*Warnings" text,
365
    "*Accepted_name_lsid" text,
366 11628 aaronmk
    is_valid_match boolean NOT NULL,
367 14122 aaronmk
    scrubbed_unique_taxon_name text,
368
    "__accepted_{genus,specific_epithet}" text[],
369 14257 aaronmk
    "[accepted_]genus__@DwC__@vegpath.org" text,
370
    "[accepted_]specificEpithet__@DwC__@vegpath.org" text,
371 14264 aaronmk
    __accepted_infraspecific_label text,
372 14265 aaronmk
    "__accepted_infraspecific_{rank,epithet}" text[],
373 14266 aaronmk
    "[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" text,
374
    "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" text,
375 14267 aaronmk
    "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" text,
376
    "[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" text,
377 14269 aaronmk
    _matched_has_accepted boolean,
378 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]))),
379 14257 aaronmk
    CONSTRAINT "[accepted_]genus__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]genus__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet}"[1]))),
380 14266 aaronmk
    CONSTRAINT "[accepted_]infraspecificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_infraspecific_{rank,epithet}"[2]))),
381 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))))),
382 14257 aaronmk
    CONSTRAINT "[accepted_]specificEpithet__@DwC__@vegpath.org" CHECK ((NOT ("[accepted_]specificEpithet__@DwC__@vegpath.org" IS DISTINCT FROM "__accepted_{genus,specific_epithet}"[2]))),
383 14267 aaronmk
    CONSTRAINT "[matched_]scientificName[_with_author]__@DwC__@vegpath.org" CHECK ((NOT ("[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS DISTINCT FROM ("*Name_matched" || COALESCE((' '::text || "*Name_matched_author"), ''::text))))),
384 14264 aaronmk
    CONSTRAINT __accepted_infraspecific_label CHECK ((NOT (__accepted_infraspecific_label IS DISTINCT FROM ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''::text), ' '::text)))),
385 14265 aaronmk
    CONSTRAINT "__accepted_infraspecific_{rank,epithet}" CHECK ((NOT ("__accepted_infraspecific_{rank,epithet}" IS DISTINCT FROM regexp_split_to_array(__accepted_infraspecific_label, ' '::text)))),
386 14269 aaronmk
    CONSTRAINT "__accepted_{genus,specific_epithet}" CHECK ((NOT ("__accepted_{genus,specific_epithet}" IS DISTINCT FROM regexp_split_to_array("*Accepted_name_species", ' '::text)))),
387
    CONSTRAINT _matched_has_accepted CHECK ((NOT (_matched_has_accepted IS DISTINCT FROM ("*Accepted_name" IS NOT NULL))))
388 10778 aaronmk
);
389 7823 aaronmk
390 9759 aaronmk
391 10778 aaronmk
--
392 13861 aaronmk
-- Name: TABLE taxon_match; Type: COMMENT; Schema: TNRS; Owner: -
393 10778 aaronmk
--
394 7823 aaronmk
395 13861 aaronmk
COMMENT ON TABLE taxon_match IS '
396 14161 aaronmk
whenever columns are renamed:
397
SELECT util.derived_cols_sync(''"TNRS".taxon_match'');
398
399 13577 aaronmk
to remove columns or add columns at the end:
400
$ rm=1 inputs/.TNRS/data.sql.run
401
$ make schemas/remake
402
403
to add columns in the middle:
404
make the changes in inputs/.TNRS/schema.sql
405
$ inputs/.TNRS/data.sql.run refresh # re-run TNRS
406
$ make schemas/remake
407 13582 aaronmk
408
to populate a new column:
409 13868 aaronmk
ALTER TABLE "TNRS".taxon_match DISABLE TRIGGER taxon_match__fill; --speeds up update
410 13861 aaronmk
UPDATE "TNRS".taxon_match SET "col" = value;
411 13582 aaronmk
	-- runtime: 30 min ("5564201 rows affected, 1624829 ms execution time")
412 14132 aaronmk
CLUSTER "TNRS".taxon_match; -- ensure rows are exported in sorted order
413 13868 aaronmk
ALTER TABLE "TNRS".taxon_match ENABLE TRIGGER taxon_match__fill;
414 13861 aaronmk
VACUUM ANALYZE "TNRS".taxon_match --remove previous rows; runtime: 1.5 min ("92633 ms")
415 13584 aaronmk
416
to add a constraint: runtime: 3 min ("173620 ms")
417 13575 aaronmk
';
418 10778 aaronmk
419
420
--
421 14254 aaronmk
-- Name: COLUMN taxon_match."__accepted_{genus,specific_epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
422
--
423
424
COMMENT ON COLUMN taxon_match."__accepted_{genus,specific_epithet}" IS '
425
derived column; = regexp_split_to_array("*Accepted_name_species", '' ''::text)
426
427
to modify:
428
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_{genus,specific_epithet}'')::util.col, $$regexp_split_to_array("*Accepted_name_species", '' ''::text)$$)::util.derived_col_def);
429 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
430 14254 aaronmk
';
431
432
433
--
434 14257 aaronmk
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
435
--
436
437
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
438
derived column; = "__accepted_{genus,specific_epithet}"[1]
439
440
to modify:
441
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet}"[1]$$)::util.derived_col_def);
442 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
443 14257 aaronmk
';
444
445
446
--
447
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
448
--
449
450
COMMENT ON COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org" IS '
451
derived column; = "__accepted_{genus,specific_epithet}"[2]
452
453
to modify:
454
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet}"[2]$$)::util.derived_col_def);
455 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
456 14257 aaronmk
';
457
458
459
--
460 14264 aaronmk
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
461
--
462
463
COMMENT ON COLUMN taxon_match.__accepted_infraspecific_label IS '
464
derived column; = ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''''), '' '')
465
466
to modify:
467
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_label'')::util.col, $$ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''''), '' '')$$)::util.derived_col_def);
468
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
469
';
470
471
472
--
473 14265 aaronmk
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
474
--
475
476
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
477
derived column; = regexp_split_to_array("__accepted_infraspecific_label", '' ''::text)
478
479
to modify:
480
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col, $$regexp_split_to_array("__accepted_infraspecific_label", '' ''::text)$$)::util.derived_col_def);
481
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
482
';
483
484
485
--
486 14266 aaronmk
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
487
--
488
489
COMMENT ON COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
490
derived column; = "__accepted_infraspecific_{rank,epithet}"[1]
491
492
to modify:
493
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);
494
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
495
';
496
497
498
--
499
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
500
--
501
502
COMMENT ON COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS '
503
derived column; = "__accepted_infraspecific_{rank,epithet}"[2]
504
505
to modify:
506
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]infraspecificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_infraspecific_{rank,epithet}"[2]$$)::util.derived_col_def);
507
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
508
';
509
510
511
--
512 14267 aaronmk
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
513
--
514
515
COMMENT ON COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
516
derived column; = "*Name_matched" || COALESCE('' ''::text || "*Name_matched_author", ''''::text)
517
518
to modify:
519
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"*Name_matched" || COALESCE('' ''::text || "*Name_matched_author", ''''::text)$$)::util.derived_col_def);
520
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
521
';
522
523
524
--
525
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
526
--
527
528
COMMENT ON COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
529
derived column; = "*Accepted_name" || COALESCE('' ''::text || "*Accepted_name_author", ''''::text)
530
531
to modify:
532
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);
533
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
534
';
535
536
537
--
538 14269 aaronmk
-- Name: COLUMN taxon_match._matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
539
--
540
541
COMMENT ON COLUMN taxon_match._matched_has_accepted IS '
542
derived column; = "*Accepted_name" IS NOT NULL
543
544
to modify:
545
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''_matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
546
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
547
';
548
549
550
--
551 13878 aaronmk
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
552
--
553
554
CREATE VIEW taxon_best_match AS
555
 SELECT taxon_match.batch,
556
    taxon_match.match_num,
557 14111 aaronmk
    taxon_match."*Name_number",
558
    taxon_match."*Name_submitted",
559
    taxon_match."*Overall_score",
560
    taxon_match."*Name_matched",
561
    taxon_match."*Name_matched_rank",
562
    taxon_match."*Name_score",
563
    taxon_match."*Name_matched_author",
564
    taxon_match."*Name_matched_url",
565
    taxon_match."*Author_matched",
566
    taxon_match."*Author_score",
567
    taxon_match."*Family_matched",
568
    taxon_match."*Family_score",
569
    taxon_match."*Name_matched_accepted_family",
570
    taxon_match."*Genus_matched",
571
    taxon_match."*Genus_score",
572
    taxon_match."*Specific_epithet_matched",
573
    taxon_match."*Specific_epithet_score",
574
    taxon_match."*Infraspecific_rank",
575
    taxon_match."*Infraspecific_epithet_matched",
576
    taxon_match."*Infraspecific_epithet_score",
577
    taxon_match."*Infraspecific_rank_2",
578
    taxon_match."*Infraspecific_epithet_2_matched",
579
    taxon_match."*Infraspecific_epithet_2_score",
580
    taxon_match."*Annotations",
581
    taxon_match."*Unmatched_terms",
582
    taxon_match."*Taxonomic_status",
583
    taxon_match."*Accepted_name",
584
    taxon_match."*Accepted_name_author",
585
    taxon_match."*Accepted_name_rank",
586
    taxon_match."*Accepted_name_url",
587
    taxon_match."*Accepted_name_species",
588
    taxon_match."*Accepted_name_family",
589
    taxon_match."*Selected",
590
    taxon_match."*Source",
591
    taxon_match."*Warnings",
592
    taxon_match."*Accepted_name_lsid",
593 13878 aaronmk
    taxon_match.is_valid_match,
594 14268 aaronmk
    taxon_match.scrubbed_unique_taxon_name,
595
    taxon_match."__accepted_{genus,specific_epithet}",
596
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
597
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
598
    taxon_match.__accepted_infraspecific_label,
599
    taxon_match."__accepted_infraspecific_{rank,epithet}",
600
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
601
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
602
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
603
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
604 13878 aaronmk
   FROM taxon_match
605 14111 aaronmk
  WHERE (taxon_match."*Selected" = 'true'::text);
606 13878 aaronmk
607
608
--
609
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
610
--
611
612
COMMENT ON VIEW taxon_best_match IS '
613
to modify:
614
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
615
SELECT __
616
$$);
617
';
618
619
620
--
621 10778 aaronmk
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
622
--
623
624
CREATE VIEW "MatchedTaxon" AS
625 14110 aaronmk
 SELECT taxon_best_match.batch,
626
    taxon_best_match.match_num,
627 14111 aaronmk
    taxon_best_match."*Name_number",
628
    taxon_best_match."*Name_submitted",
629
    taxon_best_match."*Overall_score",
630
    taxon_best_match."*Name_matched",
631
    taxon_best_match."*Name_matched_rank",
632
    taxon_best_match."*Name_score",
633
    taxon_best_match."*Name_matched_author",
634
    taxon_best_match."*Name_matched_url",
635
    taxon_best_match."*Author_matched",
636
    taxon_best_match."*Author_score",
637
    taxon_best_match."*Family_matched",
638
    taxon_best_match."*Family_score",
639
    taxon_best_match."*Name_matched_accepted_family",
640
    taxon_best_match."*Genus_matched",
641
    taxon_best_match."*Genus_score",
642
    taxon_best_match."*Specific_epithet_matched",
643
    taxon_best_match."*Specific_epithet_score",
644
    taxon_best_match."*Infraspecific_rank",
645
    taxon_best_match."*Infraspecific_epithet_matched",
646
    taxon_best_match."*Infraspecific_epithet_score",
647
    taxon_best_match."*Infraspecific_rank_2",
648
    taxon_best_match."*Infraspecific_epithet_2_matched",
649
    taxon_best_match."*Infraspecific_epithet_2_score",
650
    taxon_best_match."*Annotations",
651
    taxon_best_match."*Unmatched_terms",
652
    taxon_best_match."*Taxonomic_status",
653
    taxon_best_match."*Accepted_name",
654
    taxon_best_match."*Accepted_name_author",
655
    taxon_best_match."*Accepted_name_rank",
656
    taxon_best_match."*Accepted_name_url",
657
    taxon_best_match."*Accepted_name_species",
658
    taxon_best_match."*Accepted_name_family",
659
    taxon_best_match."*Selected",
660
    taxon_best_match."*Source",
661
    taxon_best_match."*Warnings",
662
    taxon_best_match."*Accepted_name_lsid",
663 14110 aaronmk
    taxon_best_match.is_valid_match,
664
    taxon_best_match.scrubbed_unique_taxon_name,
665 14268 aaronmk
    taxon_best_match."__accepted_{genus,specific_epithet}",
666
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
667
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
668
    taxon_best_match.__accepted_infraspecific_label,
669
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
670
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
671
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
672
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
673
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
674 14111 aaronmk
    map_taxonomic_status(taxon_best_match."*Taxonomic_status", taxon_best_match."*Accepted_name") AS "taxonomicStatus",
675 13498 aaronmk
        CASE
676 14111 aaronmk
            WHEN (taxon_best_match."*Accepted_name_rank" = 'family'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name_family", taxon_best_match."*Unmatched_terms")
677
            WHEN (taxon_best_match."*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name", taxon_best_match."*Unmatched_terms")
678
            ELSE taxon_best_match."*Accepted_name_species"
679 13498 aaronmk
        END AS accepted_morphospecies_binomial
680 14110 aaronmk
   FROM taxon_best_match;
681 10778 aaronmk
682
683
--
684 13498 aaronmk
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
685
--
686
687
COMMENT ON VIEW "MatchedTaxon" IS '
688 13501 aaronmk
to modify:
689 13845 aaronmk
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
690 13647 aaronmk
SELECT __
691 13501 aaronmk
$$);
692 13498 aaronmk
';
693
694
695
--
696 10778 aaronmk
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
697
--
698
699
CREATE VIEW "ValidMatchedTaxon" AS
700 14108 aaronmk
 SELECT "MatchedTaxon".batch,
701 14105 aaronmk
    "MatchedTaxon".match_num,
702 14111 aaronmk
    "MatchedTaxon"."*Name_number",
703
    "MatchedTaxon"."*Name_submitted",
704
    "MatchedTaxon"."*Overall_score",
705
    "MatchedTaxon"."*Name_matched",
706
    "MatchedTaxon"."*Name_matched_rank",
707
    "MatchedTaxon"."*Name_score",
708
    "MatchedTaxon"."*Name_matched_author",
709
    "MatchedTaxon"."*Name_matched_url",
710
    "MatchedTaxon"."*Author_matched",
711
    "MatchedTaxon"."*Author_score",
712
    "MatchedTaxon"."*Family_matched",
713
    "MatchedTaxon"."*Family_score",
714
    "MatchedTaxon"."*Name_matched_accepted_family",
715
    "MatchedTaxon"."*Genus_matched",
716
    "MatchedTaxon"."*Genus_score",
717
    "MatchedTaxon"."*Specific_epithet_matched",
718
    "MatchedTaxon"."*Specific_epithet_score",
719
    "MatchedTaxon"."*Infraspecific_rank",
720
    "MatchedTaxon"."*Infraspecific_epithet_matched",
721
    "MatchedTaxon"."*Infraspecific_epithet_score",
722
    "MatchedTaxon"."*Infraspecific_rank_2",
723
    "MatchedTaxon"."*Infraspecific_epithet_2_matched",
724
    "MatchedTaxon"."*Infraspecific_epithet_2_score",
725
    "MatchedTaxon"."*Annotations",
726
    "MatchedTaxon"."*Unmatched_terms",
727
    "MatchedTaxon"."*Taxonomic_status",
728
    "MatchedTaxon"."*Accepted_name",
729
    "MatchedTaxon"."*Accepted_name_author",
730
    "MatchedTaxon"."*Accepted_name_rank",
731
    "MatchedTaxon"."*Accepted_name_url",
732
    "MatchedTaxon"."*Accepted_name_species",
733
    "MatchedTaxon"."*Accepted_name_family",
734
    "MatchedTaxon"."*Selected",
735
    "MatchedTaxon"."*Source",
736
    "MatchedTaxon"."*Warnings",
737
    "MatchedTaxon"."*Accepted_name_lsid",
738 14108 aaronmk
    "MatchedTaxon".is_valid_match,
739 13800 aaronmk
    "MatchedTaxon".scrubbed_unique_taxon_name,
740 14268 aaronmk
    "MatchedTaxon"."__accepted_{genus,specific_epithet}",
741
    "MatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
742
    "MatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
743
    "MatchedTaxon".__accepted_infraspecific_label,
744
    "MatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
745
    "MatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
746
    "MatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
747
    "MatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
748
    "MatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
749 14103 aaronmk
    "MatchedTaxon"."taxonomicStatus",
750 13498 aaronmk
    "MatchedTaxon".accepted_morphospecies_binomial
751 11708 aaronmk
   FROM "MatchedTaxon"
752 14108 aaronmk
  WHERE "MatchedTaxon".is_valid_match;
753 10778 aaronmk
754
755
--
756
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
757
--
758
759 13443 aaronmk
COMMENT ON VIEW "ValidMatchedTaxon" IS '
760
to update, use * as the column list
761
';
762 10778 aaronmk
763
764
--
765
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
766
--
767
768
CREATE TABLE batch (
769
    id text NOT NULL,
770
    id_by_time text,
771
    time_submitted timestamp with time zone DEFAULT now(),
772
    client_version text
773
);
774
775
776
--
777
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
778
--
779
780
CREATE TABLE batch_download_settings (
781
    id text NOT NULL,
782
    "E-mail" text,
783
    "Id" text,
784
    "Job type" text,
785
    "Contains Id" boolean,
786
    "Start time" text,
787
    "Finish time" text,
788
    "TNRS version" text,
789
    "Sources selected" text,
790
    "Match threshold" double precision,
791
    "Classification" text,
792
    "Allow partial matches?" boolean,
793
    "Sort by source" boolean,
794
    "Constrain by higher taxonomy" boolean
795
);
796
797
798
--
799
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
800
--
801
802 13575 aaronmk
COMMENT ON TABLE batch_download_settings IS '
803
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
804
';
805 10778 aaronmk
806
807
--
808
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
809
--
810
811
CREATE TABLE client_version (
812
    id text NOT NULL,
813
    global_rev integer NOT NULL,
814
    "/lib/tnrs.py rev" integer,
815
    "/bin/tnrs_db rev" integer
816
);
817
818
819
--
820
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
821
--
822
823 13575 aaronmk
COMMENT ON TABLE client_version IS '
824
contains svn revisions
825
';
826 10778 aaronmk
827
828
--
829
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
830
--
831
832 13575 aaronmk
COMMENT ON COLUMN client_version.global_rev IS '
833
from `svn info .` > Last Changed Rev
834
';
835 10778 aaronmk
836
837
--
838
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
839
--
840
841 13575 aaronmk
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
842
from `svn info lib/tnrs.py` > Last Changed Rev
843
';
844 10778 aaronmk
845
846
--
847
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
848
--
849
850 13575 aaronmk
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
851
from `svn info bin/tnrs_db` > Last Changed Rev
852
';
853 10778 aaronmk
854
855
--
856 13866 aaronmk
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
857
--
858
859
CREATE VIEW taxon_match_input AS
860 14111 aaronmk
 SELECT taxon_match."*Name_number" AS "Name_number",
861
    taxon_match."*Name_submitted" AS "Name_submitted",
862
    taxon_match."*Overall_score" AS "Overall_score",
863
    taxon_match."*Name_matched" AS "Name_matched",
864
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
865
    taxon_match."*Name_score" AS "Name_score",
866
    taxon_match."*Name_matched_author" AS "Name_matched_author",
867
    taxon_match."*Name_matched_url" AS "Name_matched_url",
868
    taxon_match."*Author_matched" AS "Author_matched",
869
    taxon_match."*Author_score" AS "Author_score",
870
    taxon_match."*Family_matched" AS "Family_matched",
871
    taxon_match."*Family_score" AS "Family_score",
872
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
873
    taxon_match."*Genus_matched" AS "Genus_matched",
874
    taxon_match."*Genus_score" AS "Genus_score",
875
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
876
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
877
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
878
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
879
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
880
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
881
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
882
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
883
    taxon_match."*Annotations" AS "Annotations",
884
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
885
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
886
    taxon_match."*Accepted_name" AS "Accepted_name",
887
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
888
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
889
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
890
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
891
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
892
    taxon_match."*Selected" AS "Selected",
893
    taxon_match."*Source" AS "Source",
894
    taxon_match."*Warnings" AS "Warnings",
895
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
896 13866 aaronmk
   FROM taxon_match;
897
898
899
--
900
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
901
--
902
903
CREATE TABLE taxon_match_input__copy_to (
904
    "Name_number" integer,
905
    "Name_submitted" text,
906
    "Overall_score" double precision,
907
    "Name_matched" text,
908
    "Name_matched_rank" text,
909
    "Name_score" double precision,
910
    "Name_matched_author" text,
911
    "Name_matched_url" text,
912
    "Author_matched" text,
913
    "Author_score" double precision,
914
    "Family_matched" text,
915
    "Family_score" double precision,
916
    "Name_matched_accepted_family" text,
917
    "Genus_matched" text,
918
    "Genus_score" double precision,
919
    "Specific_epithet_matched" text,
920
    "Specific_epithet_score" double precision,
921
    "Infraspecific_rank" text,
922
    "Infraspecific_epithet_matched" text,
923
    "Infraspecific_epithet_score" double precision,
924
    "Infraspecific_rank_2" text,
925
    "Infraspecific_epithet_2_matched" text,
926
    "Infraspecific_epithet_2_score" double precision,
927
    "Annotations" text,
928
    "Unmatched_terms" text,
929
    "Taxonomic_status" text,
930
    "Accepted_name" text,
931
    "Accepted_name_author" text,
932
    "Accepted_name_rank" text,
933
    "Accepted_name_url" text,
934
    "Accepted_name_species" text,
935
    "Accepted_name_family" text,
936
    "Selected" text,
937
    "Source" text,
938
    "Warnings" text,
939
    "Accepted_name_lsid" text
940
);
941
942
943
--
944 11964 aaronmk
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
945
--
946
947
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
948 14111 aaronmk
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
949
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
950
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
951
    taxon_match."*Genus_matched" AS scrubbed_genus,
952
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
953
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
954
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
955
    taxon_match."*Name_matched_author" AS scrubbed_author,
956
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
957
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
958 13861 aaronmk
   FROM taxon_match;
959 11964 aaronmk
960
961
--
962 11965 aaronmk
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
963
--
964
965 13575 aaronmk
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
966 13846 aaronmk
to modify:
967
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
968
SELECT __
969
$$);
970
971 13575 aaronmk
scrubbed_family: Name_matched_accepted_family was missing from the TNRS results at one point, so Family_matched is used as a workaround to populate this. the workaround is for *accepted names only*, as no opinion names do not have an Accepted_name_family to prepend to the scrubbed name to parse.
972
';
973 11965 aaronmk
974
975
--
976 11964 aaronmk
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
977
--
978
979
CREATE VIEW taxon_scrub AS
980 13800 aaronmk
 SELECT "ValidMatchedTaxon".scrubbed_unique_taxon_name,
981 14108 aaronmk
    "ValidMatchedTaxon".batch,
982 14105 aaronmk
    "ValidMatchedTaxon".match_num,
983 14111 aaronmk
    "ValidMatchedTaxon"."*Name_number",
984
    "ValidMatchedTaxon"."*Name_submitted",
985
    "ValidMatchedTaxon"."*Overall_score",
986
    "ValidMatchedTaxon"."*Name_matched",
987
    "ValidMatchedTaxon"."*Name_matched_rank",
988
    "ValidMatchedTaxon"."*Name_score",
989
    "ValidMatchedTaxon"."*Name_matched_author",
990
    "ValidMatchedTaxon"."*Name_matched_url",
991
    "ValidMatchedTaxon"."*Author_matched",
992
    "ValidMatchedTaxon"."*Author_score",
993
    "ValidMatchedTaxon"."*Family_matched",
994
    "ValidMatchedTaxon"."*Family_score",
995
    "ValidMatchedTaxon"."*Name_matched_accepted_family",
996
    "ValidMatchedTaxon"."*Genus_matched",
997
    "ValidMatchedTaxon"."*Genus_score",
998
    "ValidMatchedTaxon"."*Specific_epithet_matched",
999
    "ValidMatchedTaxon"."*Specific_epithet_score",
1000
    "ValidMatchedTaxon"."*Infraspecific_rank",
1001
    "ValidMatchedTaxon"."*Infraspecific_epithet_matched",
1002
    "ValidMatchedTaxon"."*Infraspecific_epithet_score",
1003
    "ValidMatchedTaxon"."*Infraspecific_rank_2",
1004
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_matched",
1005
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_score",
1006
    "ValidMatchedTaxon"."*Annotations",
1007
    "ValidMatchedTaxon"."*Unmatched_terms",
1008
    "ValidMatchedTaxon"."*Taxonomic_status",
1009
    "ValidMatchedTaxon"."*Accepted_name",
1010
    "ValidMatchedTaxon"."*Accepted_name_author",
1011
    "ValidMatchedTaxon"."*Accepted_name_rank",
1012
    "ValidMatchedTaxon"."*Accepted_name_url",
1013
    "ValidMatchedTaxon"."*Accepted_name_species",
1014
    "ValidMatchedTaxon"."*Accepted_name_family",
1015
    "ValidMatchedTaxon"."*Selected",
1016
    "ValidMatchedTaxon"."*Source",
1017
    "ValidMatchedTaxon"."*Warnings",
1018
    "ValidMatchedTaxon"."*Accepted_name_lsid",
1019 14108 aaronmk
    "ValidMatchedTaxon".is_valid_match,
1020 14268 aaronmk
    "ValidMatchedTaxon"."__accepted_{genus,specific_epithet}",
1021
    "ValidMatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1022
    "ValidMatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1023
    "ValidMatchedTaxon".__accepted_infraspecific_label,
1024
    "ValidMatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1025
    "ValidMatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1026
    "ValidMatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1027
    "ValidMatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1028
    "ValidMatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1029 14103 aaronmk
    "ValidMatchedTaxon"."taxonomicStatus",
1030 13800 aaronmk
    "ValidMatchedTaxon".accepted_morphospecies_binomial,
1031
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank,
1032
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family,
1033
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus,
1034
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet,
1035
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_rank,
1036
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_epithet,
1037
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_author,
1038
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author,
1039
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_with_author,
1040 13532 aaronmk
        CASE
1041 14111 aaronmk
            WHEN ("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank = 'family'::text) THEN concat_ws(' '::text, "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family, "ValidMatchedTaxon"."*Unmatched_terms")
1042
            WHEN ("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank = 'genus'::text) THEN concat_ws(' '::text, "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author, "ValidMatchedTaxon"."*Unmatched_terms")
1043 13532 aaronmk
            ELSE (("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus || ' '::text) || "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet)
1044
        END AS scrubbed_morphospecies_binomial
1045 11964 aaronmk
   FROM ("ValidMatchedTaxon"
1046
   LEFT JOIN "taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name));
1047
1048
1049
--
1050
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1051
--
1052
1053 13443 aaronmk
COMMENT ON VIEW taxon_scrub IS '
1054 13531 aaronmk
to modify:
1055 13845 aaronmk
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1056 13647 aaronmk
SELECT __
1057 13531 aaronmk
$$);
1058 13443 aaronmk
';
1059 11964 aaronmk
1060
1061
--
1062 10778 aaronmk
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1063
--
1064
1065
ALTER TABLE ONLY batch_download_settings
1066
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1067
1068
1069
--
1070
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1071
--
1072
1073
ALTER TABLE ONLY batch
1074
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1075
1076
1077
--
1078
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1079
--
1080
1081
ALTER TABLE ONLY batch
1082
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1083
1084
1085
--
1086
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1087
--
1088
1089
ALTER TABLE ONLY client_version
1090
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1091
1092
1093
--
1094 13868 aaronmk
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1095 10778 aaronmk
--
1096
1097 13861 aaronmk
ALTER TABLE ONLY taxon_match
1098 13868 aaronmk
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1099 10778 aaronmk
1100 14125 aaronmk
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1101 10778 aaronmk
1102 14125 aaronmk
1103 10778 aaronmk
--
1104 10793 aaronmk
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1105
--
1106
1107
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1108
1109
1110
--
1111 13879 aaronmk
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1112 13589 aaronmk
--
1113
1114 14111 aaronmk
CREATE INDEX taxon_best_match__valid_match ON taxon_match USING btree ("*Name_submitted") WHERE (("*Selected" = 'true'::text) AND is_valid_match);
1115 13589 aaronmk
1116
1117
--
1118 13879 aaronmk
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1119 13874 aaronmk
--
1120
1121 14111 aaronmk
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1122 13874 aaronmk
1123
1124
--
1125 13879 aaronmk
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1126 11607 aaronmk
--
1127
1128 14111 aaronmk
CREATE UNIQUE INDEX taxon_match__one_selected_match ON taxon_match USING btree (batch, "*Name_number") WHERE ("*Selected" = 'true'::text);
1129 11607 aaronmk
1130
1131
--
1132 10778 aaronmk
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1133
--
1134
1135
CREATE TRIGGER batch__fill BEFORE INSERT OR UPDATE ON batch FOR EACH ROW EXECUTE PROCEDURE batch__fill();
1136
1137
1138
--
1139 13868 aaronmk
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1140 13866 aaronmk
--
1141
1142 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();
1143 13866 aaronmk
1144
1145
--
1146 13868 aaronmk
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1147 13567 aaronmk
--
1148
1149 13868 aaronmk
CREATE TRIGGER taxon_match__fill BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill();
1150 13567 aaronmk
1151
1152
--
1153 14122 aaronmk
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1154
--
1155
1156
CREATE TRIGGER taxon_match__fill_derived BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill_derived();
1157
1158
1159
--
1160 13868 aaronmk
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1161 13578 aaronmk
--
1162
1163 13868 aaronmk
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1164 13578 aaronmk
1165
1166
--
1167 13868 aaronmk
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1168 10778 aaronmk
--
1169
1170 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();
1171 10778 aaronmk
1172
1173
--
1174
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1175
--
1176
1177
ALTER TABLE ONLY batch
1178
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1179
1180
1181
--
1182
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1183
--
1184
1185
ALTER TABLE ONLY batch_download_settings
1186
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1187
1188
1189
--
1190 13868 aaronmk
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1191 10778 aaronmk
--
1192
1193 13861 aaronmk
ALTER TABLE ONLY taxon_match
1194 13868 aaronmk
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1195 10778 aaronmk
1196
1197
--
1198
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1199
--
1200
1201
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1202
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1203
GRANT ALL ON SCHEMA "TNRS" TO bien;
1204
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1205
1206
1207
--
1208 13861 aaronmk
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1209 10778 aaronmk
--
1210
1211 13861 aaronmk
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1212
REVOKE ALL ON TABLE taxon_match FROM bien;
1213
GRANT ALL ON TABLE taxon_match TO bien;
1214
GRANT SELECT ON TABLE taxon_match TO bien_read;
1215 10778 aaronmk
1216
1217
--
1218 13878 aaronmk
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1219
--
1220
1221
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1222
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1223
GRANT ALL ON TABLE taxon_best_match TO bien;
1224
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1225
1226
1227
--
1228 11912 aaronmk
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1229
--
1230
1231
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
1232
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
1233
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
1234
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
1235
1236
1237
--
1238
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1239
--
1240
1241
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
1242
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
1243
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
1244
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
1245
1246
1247
--
1248 13866 aaronmk
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
1249
--
1250
1251
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1252
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1253
GRANT ALL ON TABLE taxon_match_input TO bien;
1254
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1255
1256
1257
--
1258 11912 aaronmk
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
1259
--
1260
1261
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
1262
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
1263
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
1264
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
1265
1266
1267
--
1268
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1269
--
1270
1271
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
1272
REVOKE ALL ON TABLE taxon_scrub FROM bien;
1273
GRANT ALL ON TABLE taxon_scrub TO bien;
1274
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
1275
1276
1277
--
1278 10778 aaronmk
-- PostgreSQL database dump complete
1279
--