diff --git a/backend/app/api/v1/parcels.py b/backend/app/api/v1/parcels.py index 0c5c1d0a..8999bc17 100644 --- a/backend/app/api/v1/parcels.py +++ b/backend/app/api/v1/parcels.py @@ -620,7 +620,7 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str ORDER BY distance_m ASC LIMIT 30 ), - overlaps AS ( + overlap_rows AS ( SELECT cad_num, building_name, floors, @@ -637,6 +637,8 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str ORDER BY overlap_m2 DESC NULLS LAST LIMIT 5 ) + -- CTE name `overlap_rows` (НЕ `overlaps`): `OVERLAPS` — PG keyword + -- (binary operator для time-periods), парсер ругается на `overlaps AS (`. SELECT COALESCE( (SELECT json_agg(row_to_json(n) ORDER BY n.distance_m ASC) @@ -645,9 +647,9 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str ) AS neighbors, COALESCE( (SELECT json_agg(row_to_json(o) ORDER BY o.overlap_m2 DESC NULLS LAST) - FROM overlaps o), + FROM overlap_rows o), '[]'::json - ) AS overlaps + ) AS overlap_rows """), {"wkt": geom_wkt, "our_cad": our_cad_num}, ) @@ -655,7 +657,7 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str .first() ) neighbor_rows: list[dict[str, Any]] = list(row["neighbors"]) if row else [] - overlap_row: list[dict[str, Any]] = list(row["overlaps"]) if row else [] + overlap_row: list[dict[str, Any]] = list(row["overlap_rows"]) if row else [] except Exception as e: logger.warning("neighbors query failed: %s", e) return {"data_available": False, "note": f"neighbors query failed: {e}"}