tegola icon indicating copy to clipboard operation
tegola copied to clipboard

Unable to use !ZOOM! in sql query

Open KCC-IT-Admin opened this issue 3 years ago • 1 comments

I'm using a Tegola Lambda function, but when attempting to use the !ZOOM! function in my custom query it throws an exception:

2022-09-21 21:16:41 [FATAL] main.go:71: error fetching geometry type for layer (us_pos1): ERROR: syntax error at or near "ANY" (SQLSTATE 42601)

As I understand, !ZOOM! replaces with the requested Zoom level of the tile you request. Not sure why it's substituting ANY for it. if I substitute my !ZOOM! and !BBOX! variables with numbers, it works as expected in PGAdmin

the relevant toml sql:

sql = "SELECT gid, adm0code, pos1code, CASE When !ZOOM! < 5 THEN ST_AsBinary(ST_SimplifyPreserveTopology(geom,1)) When !ZOOM! < 10 THEN ST_AsBinary(ST_SimplifyPreserveTopology(geom,0.01)) When !ZOOM! >= 10 THEN ST_AsBinary(ST_SimplifyPreserveTopology(geom,0.005)) ELSE ST_AsBinary(geom) END AS geom FROM public.us_pos1 WHERE geom && !BBOX!"

The below query line works, but doesn't have the extra simplification I'm looking to get with my CASE commands. (Is simplification not supported in the Lambda version?)

sql = "SELECT gid, adm0code, pos1code, ST_AsBinary(ST_SimplifyPreserveTopology(geom,0.005)) AS geom FROM public.us_pos1 WHERE geom && !BBOX!"

KCC-IT-Admin avatar Sep 21 '22 21:09 KCC-IT-Admin

@KCC-IT-Admin can you post your tegola config? I bet if you were to define the geometry_type on the config this error would go away. What's happening is tegola is trying to infer your geometry_type during startup and is hitting an error. If you set the geometry_type in the config this step is bypassed during init.

ARolek avatar Oct 05 '22 03:10 ARolek

Duplicate of #343

pnorman avatar Oct 30 '22 01:10 pnorman

@KCC-IT-Admin can you post your tegola config? I bet if you were to define the geometry_type on the config this error would go away. What's happening is tegola is trying to infer your geometry_type during startup and is hitting an error. If you set the geometry_type in the config this step is bypassed during init.

That was it exactly. Working now as intended, thank you!

KCC-IT-Admin avatar Oct 31 '22 13:10 KCC-IT-Admin