1
|
SELECT util.search_path_append('util');
|
2
|
|
3
|
SELECT util.rename_cols(:table_str, $$
|
4
|
cultivated => *cultivated,
|
5
|
flower => *flower,
|
6
|
fruit => *fruit,
|
7
|
$$::hstore);
|
8
|
|
9
|
|
10
|
SELECT mk_derived_col((:table_str, 'specimenDonorInstitution'),
|
11
|
-- UNCCD likely = UNCC database
|
12
|
$$_map('UNCCD=>UNCC, *=>*', "herbarium")$$)
|
13
|
; -- runtime: 1 s ("Time: 1057.222 ms") @starscream
|
14
|
|
15
|
SELECT mk_derived_col((:table_str, 'cultivated__campus'),
|
16
|
/* "this refers to occurrence on the UNCC campus, but I do not know the meaning
|
17
|
of the codes. Presumably C = cultivated"
|
18
|
(https://projects.nceas.ucsb.edu/nceas/attachments/download/723/UNCC-validate_rkp_bb_rkp.xlsx#Campus)
|
19
|
*/
|
20
|
$$_map('*=>true', "campus")$$)
|
21
|
; -- runtime: 0.5 s ("Time: 353.373 ms") @starscream
|
22
|
|
23
|
SELECT mk_derived_col((:table_str, 'cultivated__main'),
|
24
|
-- for our purposes, anything non-NULL should be assumed to be cultivated
|
25
|
$$_map('*=>true', "*cultivated")$$)
|
26
|
; -- runtime: 0.5 s ("Time: 403.916 ms") @starscream
|
27
|
|
28
|
|
29
|
CREATE OR REPLACE FUNCTION map_reproductive_condition(value text)
|
30
|
RETURNS text AS
|
31
|
$BODY$
|
32
|
/*
|
33
|
"
|
34
|
Most are typos
|
35
|
|
36
|
A = absent
|
37
|
|
38
|
I = immature
|
39
|
|
40
|
M = mature
|
41
|
" (mailto:jim@habitatassessment.com?Habitat_Assessment.Jim_Matthews.to(uniola@email.unc.edu?Bob_Peet).2010-12-3:17:08.Re:_herbarium_phenology_codes_(fwd))
|
42
|
*/
|
43
|
SELECT util._map('A=>absent, I=>immature, M=>mature, *=>NULL', $1)
|
44
|
$BODY$
|
45
|
LANGUAGE sql IMMUTABLE
|
46
|
COST 100;
|
47
|
|
48
|
SELECT mk_derived_col((:table_str, 'flower'), $$map_reproductive_condition("*flower")$$); -- runtime: 0.5 s ("Time: 635.054 ms") @starscream
|
49
|
SELECT mk_derived_col((:table_str, 'fruit' ), $$map_reproductive_condition("*fruit" )$$); -- runtime: 0.5 s ("Time: 591.854 ms") @starscream
|