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`.
43 lines
1.6 KiB
PL/PgSQL
43 lines
1.6 KiB
PL/PgSQL
-- etldoc: layer_aerodrome_label[shape=record fillcolor=lightpink, style="rounded,filled", label="layer_aerodrome_label | <z10_> z10+" ] ;
|
|
|
|
CREATE OR REPLACE FUNCTION layer_aerodrome_label(bbox geometry,
|
|
zoom_level integer,
|
|
pixel_width numeric)
|
|
RETURNS TABLE
|
|
(
|
|
osm_id bigint,
|
|
geometry geometry,
|
|
name text,
|
|
name_en text,
|
|
name_de text,
|
|
tags hstore,
|
|
class text,
|
|
iata text,
|
|
icao text,
|
|
ele int,
|
|
ele_ft int
|
|
)
|
|
AS
|
|
$$
|
|
SELECT
|
|
-- etldoc: osm_aerodrome_label_point -> layer_aerodrome_label:z10_
|
|
osm_id,
|
|
geometry,
|
|
name,
|
|
COALESCE(NULLIF(name_en, ''), name) AS name_en,
|
|
COALESCE(NULLIF(name_de, ''), name, name_en) AS name_de,
|
|
tags,
|
|
CASE
|
|
%%FIELD_MAPPING: class %%
|
|
ELSE 'other'
|
|
END AS class,
|
|
NULLIF(iata, '') AS iata,
|
|
NULLIF(icao, '') AS icao,
|
|
substring(ele FROM E'^(-?\\d+)(\\D|$)')::int AS ele,
|
|
round(substring(ele FROM E'^(-?\\d+)(\\D|$)')::int * 3.2808399)::int AS ele_ft
|
|
FROM osm_aerodrome_label_point
|
|
WHERE geometry && bbox
|
|
AND zoom_level >= 10;
|
|
$$ LANGUAGE SQL IMMUTABLE
|
|
PARALLEL SAFE;
|