I would like to reformat all of our SQL to have a concise coding style. This makes it far easier to understand the code for a casual contributor, and lets us spot errors more easily. Most importantly, it makes it much easier to grep (search) the code because it is more likely to be in the same syntax Some key changes: * SQL keywords are always UPPERCASE, e.g. `SELECT WHEN AS END ...` * types, variables, aliases, and field names (identifiers) are always lower case * `LANGUAGE 'plpgsql'` is now `LANGUAGE plpgsql` (no quotes) * a few minor spacing/semicolon cleanups P.S. Per @TomPohys request, `TABLE` is spelled using upper case despite being a type for consistency with PG Docs. Same for `LANGUAGE SQL` vs `LANGUAGE plpgsql`.
41 lines
1.2 KiB
PL/PgSQL
41 lines
1.2 KiB
PL/PgSQL
CREATE OR REPLACE FUNCTION poi_class_rank(class text)
|
|
RETURNS int AS
|
|
$$
|
|
SELECT CASE class
|
|
WHEN 'hospital' THEN 20
|
|
WHEN 'railway' THEN 40
|
|
WHEN 'bus' THEN 50
|
|
WHEN 'attraction' THEN 70
|
|
WHEN 'harbor' 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 'shop' THEN 400
|
|
WHEN 'grocery' THEN 500
|
|
WHEN 'fast_food' THEN 600
|
|
WHEN 'clothing_store' THEN 700
|
|
WHEN 'bar' THEN 800
|
|
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;
|