I have been had a task: to allow a single WFS request to return two different responses depending on zoom: return usual
SELECT * FROM table
if zoom level >n, and return
SELECT ST_SimplifyPreserveTopology(geom, x) FROM table
if zoom level <=n.
I tried to do it by this definition like in advice from there:
SELECT wkb_geometry, ogc_fid, key
(CASE
WHEN %zoom_lvl% > CAST ('8' as smallint)
THEN wkb_geometry=ST_SimplifyPreserveTopology(wkb_geometry, 49::double precision)
WHEN %zoom_lvl% <= CAST ('8' as smallint)
THEN wkb_geometry = wkb_geometry
END)
from input.admin_centers_and_districts
But when I try to do it I face this
ERROR: function key(boolean) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 46
What is wrong? cast('8'smallint)
is useless.
'8'
to a number, but most of all, SQL is not comparable to procedural languages, e.g. you cannot simply assign values to variables (e.g.wkb_geometry = ST_Simplify...
). That specific error results from a missing,
betweenkey
and the following (unnecessarily bracket enclosed)CASE
statement; without the comma, PostgreSQL treats that part as a function invocation (SELECT ..., key(CASE ... END) ...
)!