CREATE OR REPLACE FUNCTION lm_class_rank(class text)
    RETURNS int AS
$$
SELECT CASE class
           WHEN 'forest' THEN 120
           ELSE 1000
           END;
$$ LANGUAGE SQL IMMUTABLE
                PARALLEL SAFE;

CREATE OR REPLACE FUNCTION lm_class(subclass text, mapping_key text)
    RETURNS text AS
$$
SELECT CASE
           %%FIELD_MAPPING: class %%
           ELSE subclass
           END;
$$ LANGUAGE SQL IMMUTABLE
                PARALLEL SAFE;
