with this sql query i can get all the points within a polygon (gid = 1652):
SELECT
polygon.gid,
points.*
FROM polygon
LEFT JOIN points
ON st_contains(polygon.the_geom, points.the_geom)
WHERE polygon.gid = 1652
i’ am trying to adapt the action_name = ‘closest_fire_station’ like this:
datasource:= format('
WITH tmp_polygon AS (
SELECT the_geom FROM polygon WHERE gid = ''%1$s''
)
SELECT
points.*,
LEFT JOIN points
ON st_contains(polygon.the_geom, points.the_geom),
''mensagem'' AS message
FROM
tmp_polygon polygon
',