1 |
10604
|
aaronmk
|
SELECT util.search_path_append('util');
|
2 |
|
|
|
3 |
10619
|
aaronmk
|
SELECT create_if_not_exists($$CREATE INDEX "Specimen.infrarank" ON $$||:table_str||$$ ("EQUIV#to:usdaRank#infrarank")$$); -- runtime: 0.1 s ("Time: 135.984 ms") @starscream
|
4 |
10604
|
aaronmk
|
|
5 |
10614
|
aaronmk
|
-- remove mismapped values
|
6 |
10619
|
aaronmk
|
UPDATE :table SET "EQUIV#to:usdaRank#infrarank" = NULL WHERE "EQUIV#to:usdaRank#infrarank" = 'L.'; -- runtime: ~0 ("Time: 2.370 ms") @starscream
|
7 |
10614
|
aaronmk
|
|
8 |
|
|
|
9 |
10604
|
aaronmk
|
SELECT mk_derived_col((:table_str, 'specimenDonorInstitution'),
|
10 |
|
|
-- UNCCD likely = UNCC database
|
11 |
10619
|
aaronmk
|
$$_map('UNCCD=>UNCC, *=>*', "specimenDonorInstitution_verbatim")$$)
|
12 |
10604
|
aaronmk
|
; -- runtime: 1 s ("Time: 1057.222 ms") @starscream
|
13 |
|
|
|
14 |
10618
|
aaronmk
|
SELECT mk_derived_col((:table_str, 'recordedBy'),
|
15 |
10619
|
aaronmk
|
$$_join("recordedBy__primary", "recordedBy__additional__1", "recordedBy__additional__2", "recordedBy__additional__3")$$)
|
16 |
10618
|
aaronmk
|
; -- runtime: 1 s ("Time: 1001.616 ms") @starscream
|
17 |
|
|
|
18 |
|
|
SELECT mk_derived_col((:table_str, 'occurrenceRemarks'),
|
19 |
10619
|
aaronmk
|
$$_join("occurrenceRemarks__1", "occurrenceRemarks__2", "occurrenceRemarks__3", "occurrenceRemarks__4")$$)
|
20 |
10618
|
aaronmk
|
; -- runtime: 1 s ("Time: 996.729 ms") @starscream
|
21 |
|
|
|
22 |
|
|
|
23 |
10604
|
aaronmk
|
SELECT mk_derived_col((:table_str, 'cultivated__campus'),
|
24 |
|
|
/* "this refers to occurrence on the UNCC campus, but I do not know the meaning
|
25 |
|
|
of the codes. Presumably C = cultivated"
|
26 |
|
|
(https://projects.nceas.ucsb.edu/nceas/attachments/download/723/UNCC-validate_rkp_bb_rkp.xlsx#Campus)
|
27 |
|
|
*/
|
28 |
10619
|
aaronmk
|
$$_map('*=>true', "cultivated__campus__verbatim")$$)
|
29 |
10604
|
aaronmk
|
; -- runtime: 0.5 s ("Time: 353.373 ms") @starscream
|
30 |
|
|
|
31 |
|
|
SELECT mk_derived_col((:table_str, 'cultivated__main'),
|
32 |
|
|
-- for our purposes, anything non-NULL should be assumed to be cultivated
|
33 |
10619
|
aaronmk
|
$$_map('*=>true', "cultivated__main__verbatim")$$)
|
34 |
10604
|
aaronmk
|
; -- runtime: 0.5 s ("Time: 403.916 ms") @starscream
|
35 |
|
|
|
36 |
10618
|
aaronmk
|
SELECT mk_derived_col((:table_str, 'cultivated'),
|
37 |
|
|
$$_alt("cultivated__main", "cultivated__campus")$$)
|
38 |
|
|
; -- runtime: 0.5 s ("Time: 394.182 ms") @starscream
|
39 |
10604
|
aaronmk
|
|
40 |
10618
|
aaronmk
|
|
41 |
10604
|
aaronmk
|
CREATE OR REPLACE FUNCTION map_reproductive_condition(value text)
|
42 |
|
|
RETURNS text AS
|
43 |
|
|
$BODY$
|
44 |
|
|
/*
|
45 |
|
|
"
|
46 |
|
|
Most are typos
|
47 |
|
|
|
48 |
|
|
A = absent
|
49 |
|
|
|
50 |
|
|
I = immature
|
51 |
|
|
|
52 |
|
|
M = mature
|
53 |
|
|
" (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))
|
54 |
|
|
*/
|
55 |
|
|
SELECT util._map('A=>absent, I=>immature, M=>mature, *=>NULL', $1)
|
56 |
|
|
$BODY$
|
57 |
|
|
LANGUAGE sql IMMUTABLE
|
58 |
|
|
COST 100;
|
59 |
|
|
|
60 |
10619
|
aaronmk
|
SELECT mk_derived_col((:table_str, 'flower'), $$map_reproductive_condition("flower_verbatim")$$); -- runtime: 0.5 s ("Time: 635.054 ms") @starscream
|
61 |
|
|
SELECT mk_derived_col((:table_str, 'fruit' ), $$map_reproductive_condition("fruit_verbatim" )$$); -- runtime: 0.5 s ("Time: 591.854 ms") @starscream
|
62 |
10618
|
aaronmk
|
|
63 |
|
|
SELECT mk_derived_col((:table_str, 'reproductiveCondition'),
|
64 |
|
|
-- using the suggested values at DwC.vegpath.org?reproductiveCondition
|
65 |
|
|
$$_join(
|
66 |
|
|
_map(('{immature,mature}'::text[] => 'in bloom' ) || '*=>NULL', "flower")
|
67 |
|
|
, _map(('{immature,mature}'::text[] => 'fruit-bearing') || '*=>NULL', "fruit" )
|
68 |
|
|
)$$)
|
69 |
|
|
; -- runtime: 1.5 s ("Time: 1433.204 ms") @starscream
|