Postgresql PostGIS中最近邻搜索错误

Postgresql PostGIS中最近邻搜索错误,postgresql,postgis,nearest-neighbor,Postgresql,Postgis,Nearest Neighbor,我正在尝试编写一个PostGIS最近邻查询,其中选择了一组坐标,并确定了与洪水最近多边形的距离。然后我想将距离分为“外部”、“闭合”或“内部”: WITH point_loc (geom) AS ( SELECT ST_SetSRID(ST_MakePoint(531673.0, 180848.2),27700) ), distances (gid, distance) AS ( SELECT fl.gid, ST_Distance(fl.

我正在尝试编写一个PostGIS最近邻查询,其中选择了一组坐标,并确定了与洪水最近多边形的距离。然后我想将距离分为“外部”、“闭合”或“内部”:

WITH 
  point_loc (geom) AS ( 
    SELECT ST_SetSRID(ST_MakePoint(531673.0, 180848.2),27700) ),
  distances (gid, distance) AS (
    SELECT  
      fl.gid,
      ST_Distance(fl.geom, p.geom) AS distance
    FROM
      point_loc p, flooding fl
    WHERE ST_DWithin(p.geom, fl.geom, 400)
  SELECT 
    gid,
    CASE WHEN distance > 300 THEN 'OUTSIDE'
         WHEN distance > 50 AND <= 300 THEN 'CLOSE'
         ELSE 'INSIDE'
    END as flood_result
  FROM distances;

我在最后一次SELECT调用中一直遇到语法错误。有人能看出我做错了什么吗?

您的第二个CTE缺少一个右括号

这一行: 其中ST_DWithinp.geom,fl.geom,400

应该是: 其中ST_DWithinp.geom,fl.geom,400