Yuri Astrakhan 6457419e0d
NOOP: Format all layer's SQL code (#917)
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`.
2020-06-08 12:19:55 -04:00

61 lines
2.2 KiB
PL/PgSQL

-- etldoc: layer_aeroway[shape=record fillcolor=lightpink, style="rounded,filled",
-- etldoc: label="layer_aeroway |<z10> z10|<z11> z11|<z12> z12|<z13> z13|<z14_> z14+" ];
CREATE OR REPLACE FUNCTION layer_aeroway(bbox geometry, zoom_level int)
RETURNS TABLE
(
geometry geometry,
class text,
ref text
)
AS
$$
SELECT geometry, aeroway AS class, ref
FROM (
-- etldoc: osm_aeroway_linestring_gen3 -> layer_aeroway:z10
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring_gen3
WHERE zoom_level = 10
UNION ALL
-- etldoc: osm_aeroway_linestring_gen2 -> layer_aeroway:z11
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring_gen2
WHERE zoom_level = 11
UNION ALL
-- etldoc: osm_aeroway_linestring_gen1 -> layer_aeroway:z12
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring_gen1
WHERE zoom_level = 12
UNION ALL
-- etldoc: osm_aeroway_linestring -> layer_aeroway:z13
-- etldoc: osm_aeroway_linestring -> layer_aeroway:z14_
SELECT geometry, aeroway, ref
FROM osm_aeroway_linestring
WHERE zoom_level >= 13
UNION ALL
-- etldoc: osm_aeroway_polygon_gen3 -> layer_aeroway:z10
-- etldoc: osm_aeroway_polygon_gen3 -> layer_aeroway:z11
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon_gen3
WHERE zoom_level BETWEEN 10 AND 11
UNION ALL
-- etldoc: osm_aeroway_polygon_gen2 -> layer_aeroway:z12
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon_gen2
WHERE zoom_level = 12
UNION ALL
-- etldoc: osm_aeroway_polygon_gen1 -> layer_aeroway:z13
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon_gen1
WHERE zoom_level = 13
UNION ALL
-- etldoc: osm_aeroway_polygon -> layer_aeroway:z14_
SELECT geometry, aeroway, ref
FROM osm_aeroway_polygon
WHERE zoom_level >= 14
) AS zoom_levels
WHERE geometry && bbox;
$$ LANGUAGE SQL IMMUTABLE
PARALLEL SAFE;