Skip to content
Advertisement

subquery in FROM must have an alias POSTGIS

I am trying using the following query on a POSTGIS (Postgres) Database. The original question: https://gis.stackexchange.com/questions/313252/postgis-sql-query-filter-by-bounding-box

SELECT row_to_json(fc) 
FROM ( 
 SELECT 'FeatureCollection' As type, 
        array_to_json(array_agg(f)) As features 
   FROM (
     SELECT 'Feature' As type, 
     ST_AsGeoJSON(lg.geom)::json As geometry, 
     row_to_json((id, name)) As properties 
  FROM lines As lg
  WHERE lg.geom && 
      ST_SETSRID(
        ST_MakeBox2D(
            ST_MakePoint(p_BB_XLong_MIN_3857, p_BB_YLat_MIN_3857),
            ST_MakePoint(p_BB_XLong_MAX_3857, p_BB_YLat_MAX_3857)),
      3857))
) As f) As fc;

However, i am getting the following Error:

subquery in FROM must have an alias

Advertisement

Answer

Seems you did not count ( and ) correctly. Remove 1 ) right before As f and that should be ok.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement