SELECT util.search_path_append('util');


-- map_nulls() derived cols
-- runtime: 1.5 min ("76.61 real") @starscream

CREATE OR REPLACE FUNCTION map_nulls__num(value text)
  RETURNS double precision AS
$BODY$
SELECT util.map_nulls('{.}', $1)::double precision
$BODY$
  LANGUAGE sql IMMUTABLE
  COST 100;

SELECT mk_derived_col((:table_str, 'minimumElevationInMeters'), $$map_nulls__num("minimumElevationInMeters_verbatim")$$); -- runtime: 40 s ("Time: 37588.218 ms") @starscream
SELECT mk_derived_col((:table_str, 'maximumElevationInMeters'), $$map_nulls__num("maximumElevationInMeters_verbatim")$$); -- runtime: 40 s ("Time: 38766.181 ms") @starscream


SELECT mk_derived_col((:table_str, 'locationRemarks'),
$$_join(_label('substrate', "substrate"), _label('vegetation', "vegetation"))$$)
; -- runtime: 45 s ("Time: 47353.897 ms") @starscream

SELECT mk_derived_col((:table_str, 'occurrenceRemarks'),
$$_join("occurrenceRemarks__main", "specimenDescription")$$)
; -- runtime: 45 s ("Time: 44831.053 ms") @starscream
