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 14277 aaronmk
	new.matched_has_accepted = (SELECT
235 14269 aaronmk
		"*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 14277 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 14277 aaronmk
    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 14275 aaronmk
to modify expr:
428 14254 aaronmk
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 14275 aaronmk
431
to rename:
432
# rename column
433
# rename CHECK constraint
434
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
435 14254 aaronmk
';
436
437
438
--
439 14257 aaronmk
-- Name: COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
440
--
441
442
COMMENT ON COLUMN taxon_match."[accepted_]genus__@DwC__@vegpath.org" IS '
443
derived column; = "__accepted_{genus,specific_epithet}"[1]
444
445 14275 aaronmk
to modify expr:
446 14257 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]genus__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet}"[1]$$)::util.derived_col_def);
447 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
448 14275 aaronmk
449
to rename:
450
# rename column
451
# rename CHECK constraint
452
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
453 14257 aaronmk
';
454
455
456
--
457
-- Name: COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
458
--
459
460
COMMENT ON COLUMN taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org" IS '
461
derived column; = "__accepted_{genus,specific_epithet}"[2]
462
463 14275 aaronmk
to modify expr:
464 14257 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[accepted_]specificEpithet__@DwC__@vegpath.org'')::util.col, $$"__accepted_{genus,specific_epithet}"[2]$$)::util.derived_col_def);
465 14258 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
466 14275 aaronmk
467
to rename:
468
# rename column
469
# rename CHECK constraint
470
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
471 14257 aaronmk
';
472
473
474
--
475 14264 aaronmk
-- Name: COLUMN taxon_match.__accepted_infraspecific_label; Type: COMMENT; Schema: TNRS; Owner: -
476
--
477
478
COMMENT ON COLUMN taxon_match.__accepted_infraspecific_label IS '
479 14273 aaronmk
derived column; = ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''''::text), '' ''::text)
480 14264 aaronmk
481 14275 aaronmk
to modify expr:
482 14273 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_label'')::util.col, $$ltrim(NULLIF(util.remove_prefix("*Accepted_name_species", "*Accepted_name", require := true), ''''::text), '' ''::text)$$)::util.derived_col_def);
483 14264 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
484 14275 aaronmk
485
to rename:
486
# rename column
487
# rename CHECK constraint
488
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
489 14264 aaronmk
';
490
491
492
--
493 14265 aaronmk
-- Name: COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}"; Type: COMMENT; Schema: TNRS; Owner: -
494
--
495
496
COMMENT ON COLUMN taxon_match."__accepted_infraspecific_{rank,epithet}" IS '
497 14273 aaronmk
derived column; = regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)
498 14265 aaronmk
499 14275 aaronmk
to modify expr:
500 14273 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''__accepted_infraspecific_{rank,epithet}'')::util.col, $$regexp_split_to_array(__accepted_infraspecific_label, '' ''::text)$$)::util.derived_col_def);
501 14265 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
502 14275 aaronmk
503
to rename:
504
# rename column
505
# rename CHECK constraint
506
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
507 14265 aaronmk
';
508
509
510
--
511 14266 aaronmk
-- Name: COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
512
--
513
514
COMMENT ON COLUMN taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org" IS '
515
derived column; = "__accepted_infraspecific_{rank,epithet}"[1]
516
517 14275 aaronmk
to modify expr:
518 14266 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);
519
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
520 14275 aaronmk
521
to rename:
522
# rename column
523
# rename CHECK constraint
524
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
525 14266 aaronmk
';
526
527
528
--
529
-- Name: COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
530
--
531
532
COMMENT ON COLUMN taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org" IS '
533
derived column; = "__accepted_infraspecific_{rank,epithet}"[2]
534
535 14275 aaronmk
to modify expr:
536 14266 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);
537
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
538 14275 aaronmk
539
to rename:
540
# rename column
541
# rename CHECK constraint
542
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
543 14266 aaronmk
';
544
545
546
--
547 14267 aaronmk
-- Name: COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
548
--
549
550
COMMENT ON COLUMN taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
551 14273 aaronmk
derived column; = "*Name_matched" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)
552 14267 aaronmk
553 14275 aaronmk
to modify expr:
554 14273 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''[matched_]scientificName[_with_author]__@DwC__@vegpath.org'')::util.col, $$"*Name_matched" || COALESCE(('' ''::text || "*Name_matched_author"), ''''::text)$$)::util.derived_col_def);
555 14267 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
556 14275 aaronmk
557
to rename:
558
# rename column
559
# rename CHECK constraint
560
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
561 14267 aaronmk
';
562
563
564
--
565
-- Name: COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"; Type: COMMENT; Schema: TNRS; Owner: -
566
--
567
568
COMMENT ON COLUMN taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org" IS '
569 14273 aaronmk
derived column; = "*Accepted_name" || COALESCE(('' ''::text || "*Accepted_name_author"), ''''::text)
570 14267 aaronmk
571 14275 aaronmk
to modify expr:
572 14273 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);
573 14267 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
574 14275 aaronmk
575
to rename:
576
# rename column
577
# rename CHECK constraint
578
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
579 14267 aaronmk
';
580
581
582
--
583 14277 aaronmk
-- Name: COLUMN taxon_match.matched_has_accepted; Type: COMMENT; Schema: TNRS; Owner: -
584 14269 aaronmk
--
585
586 14277 aaronmk
COMMENT ON COLUMN taxon_match.matched_has_accepted IS '
587 14269 aaronmk
derived column; = "*Accepted_name" IS NOT NULL
588
589 14275 aaronmk
to modify expr:
590 14277 aaronmk
SELECT util.derived_col_update(((''"TNRS".taxon_match'', ''matched_has_accepted'')::util.col, $$"*Accepted_name" IS NOT NULL$$)::util.derived_col_def);
591 14269 aaronmk
SELECT util.derived_cols_populate(''"TNRS".taxon_match''::regclass);
592 14275 aaronmk
593
to rename:
594
# rename column
595
# rename CHECK constraint
596
SELECT util.derived_cols_update(''"TNRS".taxon_match''::regclass);
597 14269 aaronmk
';
598
599
600
--
601 13878 aaronmk
-- Name: taxon_best_match; Type: VIEW; Schema: TNRS; Owner: -
602
--
603
604
CREATE VIEW taxon_best_match AS
605
 SELECT taxon_match.batch,
606
    taxon_match.match_num,
607 14111 aaronmk
    taxon_match."*Name_number",
608
    taxon_match."*Name_submitted",
609
    taxon_match."*Overall_score",
610
    taxon_match."*Name_matched",
611
    taxon_match."*Name_matched_rank",
612
    taxon_match."*Name_score",
613
    taxon_match."*Name_matched_author",
614
    taxon_match."*Name_matched_url",
615
    taxon_match."*Author_matched",
616
    taxon_match."*Author_score",
617
    taxon_match."*Family_matched",
618
    taxon_match."*Family_score",
619
    taxon_match."*Name_matched_accepted_family",
620
    taxon_match."*Genus_matched",
621
    taxon_match."*Genus_score",
622
    taxon_match."*Specific_epithet_matched",
623
    taxon_match."*Specific_epithet_score",
624
    taxon_match."*Infraspecific_rank",
625
    taxon_match."*Infraspecific_epithet_matched",
626
    taxon_match."*Infraspecific_epithet_score",
627
    taxon_match."*Infraspecific_rank_2",
628
    taxon_match."*Infraspecific_epithet_2_matched",
629
    taxon_match."*Infraspecific_epithet_2_score",
630
    taxon_match."*Annotations",
631
    taxon_match."*Unmatched_terms",
632
    taxon_match."*Taxonomic_status",
633
    taxon_match."*Accepted_name",
634
    taxon_match."*Accepted_name_author",
635
    taxon_match."*Accepted_name_rank",
636
    taxon_match."*Accepted_name_url",
637
    taxon_match."*Accepted_name_species",
638
    taxon_match."*Accepted_name_family",
639
    taxon_match."*Selected",
640
    taxon_match."*Source",
641
    taxon_match."*Warnings",
642
    taxon_match."*Accepted_name_lsid",
643 13878 aaronmk
    taxon_match.is_valid_match,
644 14268 aaronmk
    taxon_match.scrubbed_unique_taxon_name,
645
    taxon_match."__accepted_{genus,specific_epithet}",
646
    taxon_match."[accepted_]genus__@DwC__@vegpath.org",
647
    taxon_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
648
    taxon_match.__accepted_infraspecific_label,
649
    taxon_match."__accepted_infraspecific_{rank,epithet}",
650
    taxon_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
651
    taxon_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
652
    taxon_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
653
    taxon_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org"
654 13878 aaronmk
   FROM taxon_match
655 14111 aaronmk
  WHERE (taxon_match."*Selected" = 'true'::text);
656 13878 aaronmk
657
658
--
659
-- Name: VIEW taxon_best_match; Type: COMMENT; Schema: TNRS; Owner: -
660
--
661
662
COMMENT ON VIEW taxon_best_match IS '
663
to modify:
664
SELECT util.recreate_view(''"TNRS"."taxon_best_match"'', $$
665
SELECT __
666
$$);
667
';
668
669
670
--
671 10778 aaronmk
-- Name: MatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
672
--
673
674
CREATE VIEW "MatchedTaxon" AS
675 14110 aaronmk
 SELECT taxon_best_match.batch,
676
    taxon_best_match.match_num,
677 14111 aaronmk
    taxon_best_match."*Name_number",
678
    taxon_best_match."*Name_submitted",
679
    taxon_best_match."*Overall_score",
680
    taxon_best_match."*Name_matched",
681
    taxon_best_match."*Name_matched_rank",
682
    taxon_best_match."*Name_score",
683
    taxon_best_match."*Name_matched_author",
684
    taxon_best_match."*Name_matched_url",
685
    taxon_best_match."*Author_matched",
686
    taxon_best_match."*Author_score",
687
    taxon_best_match."*Family_matched",
688
    taxon_best_match."*Family_score",
689
    taxon_best_match."*Name_matched_accepted_family",
690
    taxon_best_match."*Genus_matched",
691
    taxon_best_match."*Genus_score",
692
    taxon_best_match."*Specific_epithet_matched",
693
    taxon_best_match."*Specific_epithet_score",
694
    taxon_best_match."*Infraspecific_rank",
695
    taxon_best_match."*Infraspecific_epithet_matched",
696
    taxon_best_match."*Infraspecific_epithet_score",
697
    taxon_best_match."*Infraspecific_rank_2",
698
    taxon_best_match."*Infraspecific_epithet_2_matched",
699
    taxon_best_match."*Infraspecific_epithet_2_score",
700
    taxon_best_match."*Annotations",
701
    taxon_best_match."*Unmatched_terms",
702
    taxon_best_match."*Taxonomic_status",
703
    taxon_best_match."*Accepted_name",
704
    taxon_best_match."*Accepted_name_author",
705
    taxon_best_match."*Accepted_name_rank",
706
    taxon_best_match."*Accepted_name_url",
707
    taxon_best_match."*Accepted_name_species",
708
    taxon_best_match."*Accepted_name_family",
709
    taxon_best_match."*Selected",
710
    taxon_best_match."*Source",
711
    taxon_best_match."*Warnings",
712
    taxon_best_match."*Accepted_name_lsid",
713 14110 aaronmk
    taxon_best_match.is_valid_match,
714
    taxon_best_match.scrubbed_unique_taxon_name,
715 14268 aaronmk
    taxon_best_match."__accepted_{genus,specific_epithet}",
716
    taxon_best_match."[accepted_]genus__@DwC__@vegpath.org",
717
    taxon_best_match."[accepted_]specificEpithet__@DwC__@vegpath.org",
718
    taxon_best_match.__accepted_infraspecific_label,
719
    taxon_best_match."__accepted_infraspecific_{rank,epithet}",
720
    taxon_best_match."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
721
    taxon_best_match."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
722
    taxon_best_match."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
723
    taxon_best_match."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
724 14111 aaronmk
    map_taxonomic_status(taxon_best_match."*Taxonomic_status", taxon_best_match."*Accepted_name") AS "taxonomicStatus",
725 13498 aaronmk
        CASE
726 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")
727
            WHEN (taxon_best_match."*Accepted_name_rank" = 'genus'::text) THEN concat_ws(' '::text, taxon_best_match."*Accepted_name", taxon_best_match."*Unmatched_terms")
728
            ELSE taxon_best_match."*Accepted_name_species"
729 13498 aaronmk
        END AS accepted_morphospecies_binomial
730 14110 aaronmk
   FROM taxon_best_match;
731 10778 aaronmk
732
733
--
734 13498 aaronmk
-- Name: VIEW "MatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
735
--
736
737
COMMENT ON VIEW "MatchedTaxon" IS '
738 13501 aaronmk
to modify:
739 13845 aaronmk
SELECT util.recreate_view(''"TNRS"."MatchedTaxon"'', $$
740 13647 aaronmk
SELECT __
741 13501 aaronmk
$$);
742 13498 aaronmk
';
743
744
745
--
746 10778 aaronmk
-- Name: ValidMatchedTaxon; Type: VIEW; Schema: TNRS; Owner: -
747
--
748
749
CREATE VIEW "ValidMatchedTaxon" AS
750 14108 aaronmk
 SELECT "MatchedTaxon".batch,
751 14105 aaronmk
    "MatchedTaxon".match_num,
752 14111 aaronmk
    "MatchedTaxon"."*Name_number",
753
    "MatchedTaxon"."*Name_submitted",
754
    "MatchedTaxon"."*Overall_score",
755
    "MatchedTaxon"."*Name_matched",
756
    "MatchedTaxon"."*Name_matched_rank",
757
    "MatchedTaxon"."*Name_score",
758
    "MatchedTaxon"."*Name_matched_author",
759
    "MatchedTaxon"."*Name_matched_url",
760
    "MatchedTaxon"."*Author_matched",
761
    "MatchedTaxon"."*Author_score",
762
    "MatchedTaxon"."*Family_matched",
763
    "MatchedTaxon"."*Family_score",
764
    "MatchedTaxon"."*Name_matched_accepted_family",
765
    "MatchedTaxon"."*Genus_matched",
766
    "MatchedTaxon"."*Genus_score",
767
    "MatchedTaxon"."*Specific_epithet_matched",
768
    "MatchedTaxon"."*Specific_epithet_score",
769
    "MatchedTaxon"."*Infraspecific_rank",
770
    "MatchedTaxon"."*Infraspecific_epithet_matched",
771
    "MatchedTaxon"."*Infraspecific_epithet_score",
772
    "MatchedTaxon"."*Infraspecific_rank_2",
773
    "MatchedTaxon"."*Infraspecific_epithet_2_matched",
774
    "MatchedTaxon"."*Infraspecific_epithet_2_score",
775
    "MatchedTaxon"."*Annotations",
776
    "MatchedTaxon"."*Unmatched_terms",
777
    "MatchedTaxon"."*Taxonomic_status",
778
    "MatchedTaxon"."*Accepted_name",
779
    "MatchedTaxon"."*Accepted_name_author",
780
    "MatchedTaxon"."*Accepted_name_rank",
781
    "MatchedTaxon"."*Accepted_name_url",
782
    "MatchedTaxon"."*Accepted_name_species",
783
    "MatchedTaxon"."*Accepted_name_family",
784
    "MatchedTaxon"."*Selected",
785
    "MatchedTaxon"."*Source",
786
    "MatchedTaxon"."*Warnings",
787
    "MatchedTaxon"."*Accepted_name_lsid",
788 14108 aaronmk
    "MatchedTaxon".is_valid_match,
789 13800 aaronmk
    "MatchedTaxon".scrubbed_unique_taxon_name,
790 14268 aaronmk
    "MatchedTaxon"."__accepted_{genus,specific_epithet}",
791
    "MatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
792
    "MatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
793
    "MatchedTaxon".__accepted_infraspecific_label,
794
    "MatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
795
    "MatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
796
    "MatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
797
    "MatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
798
    "MatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
799 14103 aaronmk
    "MatchedTaxon"."taxonomicStatus",
800 13498 aaronmk
    "MatchedTaxon".accepted_morphospecies_binomial
801 11708 aaronmk
   FROM "MatchedTaxon"
802 14108 aaronmk
  WHERE "MatchedTaxon".is_valid_match;
803 10778 aaronmk
804
805
--
806
-- Name: VIEW "ValidMatchedTaxon"; Type: COMMENT; Schema: TNRS; Owner: -
807
--
808
809 13443 aaronmk
COMMENT ON VIEW "ValidMatchedTaxon" IS '
810
to update, use * as the column list
811
';
812 10778 aaronmk
813
814
--
815
-- Name: batch; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
816
--
817
818
CREATE TABLE batch (
819
    id text NOT NULL,
820
    id_by_time text,
821
    time_submitted timestamp with time zone DEFAULT now(),
822
    client_version text
823
);
824
825
826
--
827
-- Name: batch_download_settings; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
828
--
829
830
CREATE TABLE batch_download_settings (
831
    id text NOT NULL,
832
    "E-mail" text,
833
    "Id" text,
834
    "Job type" text,
835
    "Contains Id" boolean,
836
    "Start time" text,
837
    "Finish time" text,
838
    "TNRS version" text,
839
    "Sources selected" text,
840
    "Match threshold" double precision,
841
    "Classification" text,
842
    "Allow partial matches?" boolean,
843
    "Sort by source" boolean,
844
    "Constrain by higher taxonomy" boolean
845
);
846
847
848
--
849
-- Name: TABLE batch_download_settings; Type: COMMENT; Schema: TNRS; Owner: -
850
--
851
852 13575 aaronmk
COMMENT ON TABLE batch_download_settings IS '
853
stores data from http://tnrs.iplantcollaborative.org/TNRSapp.html > Submit List > results section > Download settings > settings.txt
854
';
855 10778 aaronmk
856
857
--
858
-- Name: client_version; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
859
--
860
861
CREATE TABLE client_version (
862
    id text NOT NULL,
863
    global_rev integer NOT NULL,
864
    "/lib/tnrs.py rev" integer,
865
    "/bin/tnrs_db rev" integer
866
);
867
868
869
--
870
-- Name: TABLE client_version; Type: COMMENT; Schema: TNRS; Owner: -
871
--
872
873 13575 aaronmk
COMMENT ON TABLE client_version IS '
874
contains svn revisions
875
';
876 10778 aaronmk
877
878
--
879
-- Name: COLUMN client_version.global_rev; Type: COMMENT; Schema: TNRS; Owner: -
880
--
881
882 13575 aaronmk
COMMENT ON COLUMN client_version.global_rev IS '
883
from `svn info .` > Last Changed Rev
884
';
885 10778 aaronmk
886
887
--
888
-- Name: COLUMN client_version."/lib/tnrs.py rev"; Type: COMMENT; Schema: TNRS; Owner: -
889
--
890
891 13575 aaronmk
COMMENT ON COLUMN client_version."/lib/tnrs.py rev" IS '
892
from `svn info lib/tnrs.py` > Last Changed Rev
893
';
894 10778 aaronmk
895
896
--
897
-- Name: COLUMN client_version."/bin/tnrs_db rev"; Type: COMMENT; Schema: TNRS; Owner: -
898
--
899
900 13575 aaronmk
COMMENT ON COLUMN client_version."/bin/tnrs_db rev" IS '
901
from `svn info bin/tnrs_db` > Last Changed Rev
902
';
903 10778 aaronmk
904
905
--
906 13866 aaronmk
-- Name: taxon_match_input; Type: VIEW; Schema: TNRS; Owner: -
907
--
908
909
CREATE VIEW taxon_match_input AS
910 14111 aaronmk
 SELECT taxon_match."*Name_number" AS "Name_number",
911
    taxon_match."*Name_submitted" AS "Name_submitted",
912
    taxon_match."*Overall_score" AS "Overall_score",
913
    taxon_match."*Name_matched" AS "Name_matched",
914
    taxon_match."*Name_matched_rank" AS "Name_matched_rank",
915
    taxon_match."*Name_score" AS "Name_score",
916
    taxon_match."*Name_matched_author" AS "Name_matched_author",
917
    taxon_match."*Name_matched_url" AS "Name_matched_url",
918
    taxon_match."*Author_matched" AS "Author_matched",
919
    taxon_match."*Author_score" AS "Author_score",
920
    taxon_match."*Family_matched" AS "Family_matched",
921
    taxon_match."*Family_score" AS "Family_score",
922
    taxon_match."*Name_matched_accepted_family" AS "Name_matched_accepted_family",
923
    taxon_match."*Genus_matched" AS "Genus_matched",
924
    taxon_match."*Genus_score" AS "Genus_score",
925
    taxon_match."*Specific_epithet_matched" AS "Specific_epithet_matched",
926
    taxon_match."*Specific_epithet_score" AS "Specific_epithet_score",
927
    taxon_match."*Infraspecific_rank" AS "Infraspecific_rank",
928
    taxon_match."*Infraspecific_epithet_matched" AS "Infraspecific_epithet_matched",
929
    taxon_match."*Infraspecific_epithet_score" AS "Infraspecific_epithet_score",
930
    taxon_match."*Infraspecific_rank_2" AS "Infraspecific_rank_2",
931
    taxon_match."*Infraspecific_epithet_2_matched" AS "Infraspecific_epithet_2_matched",
932
    taxon_match."*Infraspecific_epithet_2_score" AS "Infraspecific_epithet_2_score",
933
    taxon_match."*Annotations" AS "Annotations",
934
    taxon_match."*Unmatched_terms" AS "Unmatched_terms",
935
    taxon_match."*Taxonomic_status" AS "Taxonomic_status",
936
    taxon_match."*Accepted_name" AS "Accepted_name",
937
    taxon_match."*Accepted_name_author" AS "Accepted_name_author",
938
    taxon_match."*Accepted_name_rank" AS "Accepted_name_rank",
939
    taxon_match."*Accepted_name_url" AS "Accepted_name_url",
940
    taxon_match."*Accepted_name_species" AS "Accepted_name_species",
941
    taxon_match."*Accepted_name_family" AS "Accepted_name_family",
942
    taxon_match."*Selected" AS "Selected",
943
    taxon_match."*Source" AS "Source",
944
    taxon_match."*Warnings" AS "Warnings",
945
    taxon_match."*Accepted_name_lsid" AS "Accepted_name_lsid"
946 13866 aaronmk
   FROM taxon_match;
947
948
949
--
950
-- Name: taxon_match_input__copy_to; Type: TABLE; Schema: TNRS; Owner: -; Tablespace:
951
--
952
953
CREATE TABLE taxon_match_input__copy_to (
954
    "Name_number" integer,
955
    "Name_submitted" text,
956
    "Overall_score" double precision,
957
    "Name_matched" text,
958
    "Name_matched_rank" text,
959
    "Name_score" double precision,
960
    "Name_matched_author" text,
961
    "Name_matched_url" text,
962
    "Author_matched" text,
963
    "Author_score" double precision,
964
    "Family_matched" text,
965
    "Family_score" double precision,
966
    "Name_matched_accepted_family" text,
967
    "Genus_matched" text,
968
    "Genus_score" double precision,
969
    "Specific_epithet_matched" text,
970
    "Specific_epithet_score" double precision,
971
    "Infraspecific_rank" text,
972
    "Infraspecific_epithet_matched" text,
973
    "Infraspecific_epithet_score" double precision,
974
    "Infraspecific_rank_2" text,
975
    "Infraspecific_epithet_2_matched" text,
976
    "Infraspecific_epithet_2_score" double precision,
977
    "Annotations" text,
978
    "Unmatched_terms" text,
979
    "Taxonomic_status" text,
980
    "Accepted_name" text,
981
    "Accepted_name_author" text,
982
    "Accepted_name_rank" text,
983
    "Accepted_name_url" text,
984
    "Accepted_name_species" text,
985
    "Accepted_name_family" text,
986
    "Selected" text,
987
    "Source" text,
988
    "Warnings" text,
989
    "Accepted_name_lsid" text
990
);
991
992
993
--
994 11964 aaronmk
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: VIEW; Schema: TNRS; Owner: -
995
--
996
997
CREATE VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" AS
998 14111 aaronmk
 SELECT taxon_match."*Name_submitted" AS scrubbed_unique_taxon_name,
999
    taxon_match."*Name_matched_rank" AS scrubbed_taxon_rank,
1000
    COALESCE(taxon_match."*Name_matched_accepted_family", taxon_match."*Family_matched") AS scrubbed_family,
1001
    taxon_match."*Genus_matched" AS scrubbed_genus,
1002
    taxon_match."*Specific_epithet_matched" AS scrubbed_specific_epithet,
1003
    taxon_match."*Infraspecific_rank" AS scrubbed_infraspecific_rank,
1004
    taxon_match."*Infraspecific_epithet_matched" AS scrubbed_infraspecific_epithet,
1005
    taxon_match."*Name_matched_author" AS scrubbed_author,
1006
    taxon_match."*Name_matched" AS scrubbed_taxon_name_no_author,
1007
    (taxon_match."*Name_matched" || COALESCE((' '::text || taxon_match."*Name_matched_author"), ''::text)) AS scrubbed_taxon_name_with_author
1008 13861 aaronmk
   FROM taxon_match;
1009 11964 aaronmk
1010
1011
--
1012 11965 aaronmk
-- Name: VIEW "taxon_scrub.scrubbed_unique_taxon_name.*"; Type: COMMENT; Schema: TNRS; Owner: -
1013
--
1014
1015 13575 aaronmk
COMMENT ON VIEW "taxon_scrub.scrubbed_unique_taxon_name.*" IS '
1016 13846 aaronmk
to modify:
1017
SELECT util.recreate_view(''"TNRS"."taxon_scrub.scrubbed_unique_taxon_name.*"'', $$
1018
SELECT __
1019
$$);
1020
1021 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.
1022
';
1023 11965 aaronmk
1024
1025
--
1026 11964 aaronmk
-- Name: taxon_scrub; Type: VIEW; Schema: TNRS; Owner: -
1027
--
1028
1029
CREATE VIEW taxon_scrub AS
1030 13800 aaronmk
 SELECT "ValidMatchedTaxon".scrubbed_unique_taxon_name,
1031 14108 aaronmk
    "ValidMatchedTaxon".batch,
1032 14105 aaronmk
    "ValidMatchedTaxon".match_num,
1033 14111 aaronmk
    "ValidMatchedTaxon"."*Name_number",
1034
    "ValidMatchedTaxon"."*Name_submitted",
1035
    "ValidMatchedTaxon"."*Overall_score",
1036
    "ValidMatchedTaxon"."*Name_matched",
1037
    "ValidMatchedTaxon"."*Name_matched_rank",
1038
    "ValidMatchedTaxon"."*Name_score",
1039
    "ValidMatchedTaxon"."*Name_matched_author",
1040
    "ValidMatchedTaxon"."*Name_matched_url",
1041
    "ValidMatchedTaxon"."*Author_matched",
1042
    "ValidMatchedTaxon"."*Author_score",
1043
    "ValidMatchedTaxon"."*Family_matched",
1044
    "ValidMatchedTaxon"."*Family_score",
1045
    "ValidMatchedTaxon"."*Name_matched_accepted_family",
1046
    "ValidMatchedTaxon"."*Genus_matched",
1047
    "ValidMatchedTaxon"."*Genus_score",
1048
    "ValidMatchedTaxon"."*Specific_epithet_matched",
1049
    "ValidMatchedTaxon"."*Specific_epithet_score",
1050
    "ValidMatchedTaxon"."*Infraspecific_rank",
1051
    "ValidMatchedTaxon"."*Infraspecific_epithet_matched",
1052
    "ValidMatchedTaxon"."*Infraspecific_epithet_score",
1053
    "ValidMatchedTaxon"."*Infraspecific_rank_2",
1054
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_matched",
1055
    "ValidMatchedTaxon"."*Infraspecific_epithet_2_score",
1056
    "ValidMatchedTaxon"."*Annotations",
1057
    "ValidMatchedTaxon"."*Unmatched_terms",
1058
    "ValidMatchedTaxon"."*Taxonomic_status",
1059
    "ValidMatchedTaxon"."*Accepted_name",
1060
    "ValidMatchedTaxon"."*Accepted_name_author",
1061
    "ValidMatchedTaxon"."*Accepted_name_rank",
1062
    "ValidMatchedTaxon"."*Accepted_name_url",
1063
    "ValidMatchedTaxon"."*Accepted_name_species",
1064
    "ValidMatchedTaxon"."*Accepted_name_family",
1065
    "ValidMatchedTaxon"."*Selected",
1066
    "ValidMatchedTaxon"."*Source",
1067
    "ValidMatchedTaxon"."*Warnings",
1068
    "ValidMatchedTaxon"."*Accepted_name_lsid",
1069 14108 aaronmk
    "ValidMatchedTaxon".is_valid_match,
1070 14268 aaronmk
    "ValidMatchedTaxon"."__accepted_{genus,specific_epithet}",
1071
    "ValidMatchedTaxon"."[accepted_]genus__@DwC__@vegpath.org",
1072
    "ValidMatchedTaxon"."[accepted_]specificEpithet__@DwC__@vegpath.org",
1073
    "ValidMatchedTaxon".__accepted_infraspecific_label,
1074
    "ValidMatchedTaxon"."__accepted_infraspecific_{rank,epithet}",
1075
    "ValidMatchedTaxon"."[accepted_]Infraspecific_rank[_abbr]__@TNRS__@vegpath.org",
1076
    "ValidMatchedTaxon"."[accepted_]infraspecificEpithet__@DwC__@vegpath.org",
1077
    "ValidMatchedTaxon"."[matched_]scientificName[_with_author]__@DwC__@vegpath.org",
1078
    "ValidMatchedTaxon"."[accepted_]scientificName[_with_author]__@DwC__@vegpath.org",
1079 14103 aaronmk
    "ValidMatchedTaxon"."taxonomicStatus",
1080 13800 aaronmk
    "ValidMatchedTaxon".accepted_morphospecies_binomial,
1081
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank,
1082
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_family,
1083
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus,
1084
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet,
1085
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_rank,
1086
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_infraspecific_epithet,
1087
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_author,
1088
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author,
1089
    "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_with_author,
1090 13532 aaronmk
        CASE
1091 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")
1092
            WHEN ("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_rank = 'genus'::text) THEN concat_ws(' '::text, "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_taxon_name_no_author, "ValidMatchedTaxon"."*Unmatched_terms")
1093 13532 aaronmk
            ELSE (("taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_genus || ' '::text) || "taxon_scrub.scrubbed_unique_taxon_name.*".scrubbed_specific_epithet)
1094
        END AS scrubbed_morphospecies_binomial
1095 11964 aaronmk
   FROM ("ValidMatchedTaxon"
1096
   LEFT JOIN "taxon_scrub.scrubbed_unique_taxon_name.*" USING (scrubbed_unique_taxon_name));
1097
1098
1099
--
1100
-- Name: VIEW taxon_scrub; Type: COMMENT; Schema: TNRS; Owner: -
1101
--
1102
1103 13443 aaronmk
COMMENT ON VIEW taxon_scrub IS '
1104 13531 aaronmk
to modify:
1105 13845 aaronmk
SELECT util.recreate_view(''"TNRS".taxon_scrub'', $$
1106 13647 aaronmk
SELECT __
1107 13531 aaronmk
$$);
1108 13443 aaronmk
';
1109 11964 aaronmk
1110
1111
--
1112 10778 aaronmk
-- Name: batch_download_settings_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1113
--
1114
1115
ALTER TABLE ONLY batch_download_settings
1116
    ADD CONSTRAINT batch_download_settings_pkey PRIMARY KEY (id);
1117
1118
1119
--
1120
-- Name: batch_id_by_time_key; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1121
--
1122
1123
ALTER TABLE ONLY batch
1124
    ADD CONSTRAINT batch_id_by_time_key UNIQUE (id_by_time);
1125
1126
1127
--
1128
-- Name: batch_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1129
--
1130
1131
ALTER TABLE ONLY batch
1132
    ADD CONSTRAINT batch_pkey PRIMARY KEY (id);
1133
1134
1135
--
1136
-- Name: client_version_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1137
--
1138
1139
ALTER TABLE ONLY client_version
1140
    ADD CONSTRAINT client_version_pkey PRIMARY KEY (id);
1141
1142
1143
--
1144 13868 aaronmk
-- Name: taxon_match_pkey; Type: CONSTRAINT; Schema: TNRS; Owner: -; Tablespace:
1145 10778 aaronmk
--
1146
1147 13861 aaronmk
ALTER TABLE ONLY taxon_match
1148 13868 aaronmk
    ADD CONSTRAINT taxon_match_pkey PRIMARY KEY (batch, match_num);
1149 10778 aaronmk
1150 14125 aaronmk
ALTER TABLE taxon_match CLUSTER ON taxon_match_pkey;
1151 10778 aaronmk
1152 14125 aaronmk
1153 10778 aaronmk
--
1154 10793 aaronmk
-- Name: batch_client_version_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1155
--
1156
1157
CREATE INDEX batch_client_version_idx ON batch USING btree (client_version);
1158
1159
1160
--
1161 13879 aaronmk
-- Name: taxon_best_match__valid_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1162 13589 aaronmk
--
1163
1164 14111 aaronmk
CREATE INDEX taxon_best_match__valid_match ON taxon_match USING btree ("*Name_submitted") WHERE (("*Selected" = 'true'::text) AND is_valid_match);
1165 13589 aaronmk
1166
1167
--
1168 13879 aaronmk
-- Name: taxon_match_Name_submitted_idx; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1169 13874 aaronmk
--
1170
1171 14111 aaronmk
CREATE INDEX "taxon_match_Name_submitted_idx" ON taxon_match USING btree ("*Name_submitted");
1172 13874 aaronmk
1173
1174
--
1175 13879 aaronmk
-- Name: taxon_match__one_selected_match; Type: INDEX; Schema: TNRS; Owner: -; Tablespace:
1176 11607 aaronmk
--
1177
1178 14111 aaronmk
CREATE UNIQUE INDEX taxon_match__one_selected_match ON taxon_match USING btree (batch, "*Name_number") WHERE ("*Selected" = 'true'::text);
1179 11607 aaronmk
1180
1181
--
1182 10778 aaronmk
-- Name: batch__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1183
--
1184
1185
CREATE TRIGGER batch__fill BEFORE INSERT OR UPDATE ON batch FOR EACH ROW EXECUTE PROCEDURE batch__fill();
1186
1187
1188
--
1189 13868 aaronmk
-- Name: taxon_match__batch_begin; Type: TRIGGER; Schema: TNRS; Owner: -
1190 13866 aaronmk
--
1191
1192 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();
1193 13866 aaronmk
1194
1195
--
1196 13868 aaronmk
-- Name: taxon_match__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1197 13567 aaronmk
--
1198
1199 13868 aaronmk
CREATE TRIGGER taxon_match__fill BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill();
1200 13567 aaronmk
1201
1202
--
1203 14122 aaronmk
-- Name: taxon_match__fill_derived; Type: TRIGGER; Schema: TNRS; Owner: -
1204
--
1205
1206
CREATE TRIGGER taxon_match__fill_derived BEFORE INSERT OR UPDATE ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__fill_derived();
1207
1208
1209
--
1210 13868 aaronmk
-- Name: taxon_match__match_num__fill; Type: TRIGGER; Schema: TNRS; Owner: -
1211 13578 aaronmk
--
1212
1213 13868 aaronmk
CREATE TRIGGER taxon_match__match_num__fill BEFORE INSERT ON taxon_match FOR EACH ROW EXECUTE PROCEDURE taxon_match__match_num__fill();
1214 13578 aaronmk
1215
1216
--
1217 13868 aaronmk
-- Name: taxon_match_input__copy_to__insert; Type: TRIGGER; Schema: TNRS; Owner: -
1218 10778 aaronmk
--
1219
1220 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();
1221 10778 aaronmk
1222
1223
--
1224
-- Name: batch_client_version_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1225
--
1226
1227
ALTER TABLE ONLY batch
1228
    ADD CONSTRAINT batch_client_version_fkey FOREIGN KEY (client_version) REFERENCES client_version(id) ON UPDATE CASCADE ON DELETE CASCADE;
1229
1230
1231
--
1232
-- Name: batch_download_settings_id_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1233
--
1234
1235
ALTER TABLE ONLY batch_download_settings
1236
    ADD CONSTRAINT batch_download_settings_id_fkey FOREIGN KEY (id) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1237
1238
1239
--
1240 13868 aaronmk
-- Name: taxon_match_batch_fkey; Type: FK CONSTRAINT; Schema: TNRS; Owner: -
1241 10778 aaronmk
--
1242
1243 13861 aaronmk
ALTER TABLE ONLY taxon_match
1244 13868 aaronmk
    ADD CONSTRAINT taxon_match_batch_fkey FOREIGN KEY (batch) REFERENCES batch(id) ON UPDATE CASCADE ON DELETE CASCADE;
1245 10778 aaronmk
1246
1247
--
1248
-- Name: TNRS; Type: ACL; Schema: -; Owner: -
1249
--
1250
1251
REVOKE ALL ON SCHEMA "TNRS" FROM PUBLIC;
1252
REVOKE ALL ON SCHEMA "TNRS" FROM bien;
1253
GRANT ALL ON SCHEMA "TNRS" TO bien;
1254
GRANT USAGE ON SCHEMA "TNRS" TO bien_read;
1255
1256
1257
--
1258 13861 aaronmk
-- Name: taxon_match; Type: ACL; Schema: TNRS; Owner: -
1259 10778 aaronmk
--
1260
1261 13861 aaronmk
REVOKE ALL ON TABLE taxon_match FROM PUBLIC;
1262
REVOKE ALL ON TABLE taxon_match FROM bien;
1263
GRANT ALL ON TABLE taxon_match TO bien;
1264
GRANT SELECT ON TABLE taxon_match TO bien_read;
1265 10778 aaronmk
1266
1267
--
1268 13878 aaronmk
-- Name: taxon_best_match; Type: ACL; Schema: TNRS; Owner: -
1269
--
1270
1271
REVOKE ALL ON TABLE taxon_best_match FROM PUBLIC;
1272
REVOKE ALL ON TABLE taxon_best_match FROM bien;
1273
GRANT ALL ON TABLE taxon_best_match TO bien;
1274
GRANT SELECT ON TABLE taxon_best_match TO bien_read;
1275
1276
1277
--
1278 11912 aaronmk
-- Name: MatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1279
--
1280
1281
REVOKE ALL ON TABLE "MatchedTaxon" FROM PUBLIC;
1282
REVOKE ALL ON TABLE "MatchedTaxon" FROM bien;
1283
GRANT ALL ON TABLE "MatchedTaxon" TO bien;
1284
GRANT SELECT ON TABLE "MatchedTaxon" TO bien_read;
1285
1286
1287
--
1288
-- Name: ValidMatchedTaxon; Type: ACL; Schema: TNRS; Owner: -
1289
--
1290
1291
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM PUBLIC;
1292
REVOKE ALL ON TABLE "ValidMatchedTaxon" FROM bien;
1293
GRANT ALL ON TABLE "ValidMatchedTaxon" TO bien;
1294
GRANT SELECT ON TABLE "ValidMatchedTaxon" TO bien_read;
1295
1296
1297
--
1298 13866 aaronmk
-- Name: taxon_match_input; Type: ACL; Schema: TNRS; Owner: -
1299
--
1300
1301
REVOKE ALL ON TABLE taxon_match_input FROM PUBLIC;
1302
REVOKE ALL ON TABLE taxon_match_input FROM bien;
1303
GRANT ALL ON TABLE taxon_match_input TO bien;
1304
GRANT SELECT ON TABLE taxon_match_input TO bien_read;
1305
1306
1307
--
1308 11912 aaronmk
-- Name: taxon_scrub.scrubbed_unique_taxon_name.*; Type: ACL; Schema: TNRS; Owner: -
1309
--
1310
1311
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM PUBLIC;
1312
REVOKE ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" FROM bien;
1313
GRANT ALL ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien;
1314
GRANT SELECT ON TABLE "taxon_scrub.scrubbed_unique_taxon_name.*" TO bien_read;
1315
1316
1317
--
1318
-- Name: taxon_scrub; Type: ACL; Schema: TNRS; Owner: -
1319
--
1320
1321
REVOKE ALL ON TABLE taxon_scrub FROM PUBLIC;
1322
REVOKE ALL ON TABLE taxon_scrub FROM bien;
1323
GRANT ALL ON TABLE taxon_scrub TO bien;
1324
GRANT SELECT ON TABLE taxon_scrub TO bien_read;
1325
1326
1327
--
1328 10778 aaronmk
-- PostgreSQL database dump complete
1329
--