CREATE OR REPLACE FUNCTION poi_class_rank(class text)
    RETURNS int AS
$$
SELECT CASE class
           WHEN 'hospital' THEN 20
           WHEN 'airport' THEN 30
           WHEN 'railway' THEN 40
           WHEN 'aerialway' THEN 40
           WHEN 'heliport' THEN 45
           WHEN 'taxi' THEN 50
           WHEN 'harbor' THEN 55
           WHEN 'library' THEN 60
           WHEN 'bus' THEN 70
           WHEN 'attraction' THEN 75
           WHEN 'college' THEN 80
           WHEN 'school' THEN 85
           WHEN 'stadium' THEN 90
           WHEN 'zoo' THEN 95
           WHEN 'town_hall' THEN 100
           WHEN 'campsite' THEN 110
           WHEN 'cemetery' THEN 115
           WHEN 'park' THEN 120
           WHEN 'library' THEN 130
           WHEN 'police' THEN 135
           WHEN 'post' THEN 140
           WHEN 'golf' THEN 150
           WHEN 'entrance' THEN 250
           WHEN 'parking' THEN 300
           WHEN 'car_parking' THEN 300
           WHEN 'charging_station' THEN 350
           WHEN 'fuel' THEN 350
           WHEN 'bicycle_parking' THEN 390
           WHEN 'motorcycle_parking' THEN 390
           WHEN 'fast_food' THEN 400
           WHEN 'ice_cream' THEN 400
           WHEN 'bar' THEN 450
           WHEN 'cafe' THEN 450
           WHEN 'grocery' THEN 450
           WHEN 'shop' THEN 500
           WHEN 'optician' THEN 500
           WHEN 'furniture' THEN 500
           WHEN 'jewelry' THEN 500
           WHEN 'toys' THEN 500
           WHEN 'newsagent' THEN 500
           WHEN 'paint' THEN 500
           WHEN 'electronics' THEN 500
           WHEN 'garden_centre' THEN 500
           WHEN 'community_centre' THEN 600
           WHEN 'mobile_phone' THEN 700
           WHEN 'shoes' THEN 700
           WHEN 'clothing_store' THEN 700
           WHEN 'florist' THEN 750
           WHEN 'dog_park' THEN 800
           WHEN 'pitch' THEN 800
           WHEN 'power_tower' then 900
           WHEN 'wind_mill' then 900
           WHEN 'water_tower' then 900
           WHEN 'communications_tower' then 900
           WHEN 'wind_turbine' then 900
           ELSE 1000
           END;
$$ LANGUAGE SQL IMMUTABLE
                PARALLEL SAFE;

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