fix(parcels): rename CTE overlaps → overlap_rows (#1196 hotfix) #1197
1 changed files with 6 additions and 4 deletions
|
|
@ -620,7 +620,7 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str
|
||||||
ORDER BY distance_m ASC
|
ORDER BY distance_m ASC
|
||||||
LIMIT 30
|
LIMIT 30
|
||||||
),
|
),
|
||||||
overlaps AS (
|
overlap_rows AS (
|
||||||
SELECT cad_num,
|
SELECT cad_num,
|
||||||
building_name,
|
building_name,
|
||||||
floors,
|
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
|
ORDER BY overlap_m2 DESC NULLS LAST
|
||||||
LIMIT 5
|
LIMIT 5
|
||||||
)
|
)
|
||||||
|
-- CTE name `overlap_rows` (НЕ `overlaps`): `OVERLAPS` — PG keyword
|
||||||
|
-- (binary operator для time-periods), парсер ругается на `overlaps AS (`.
|
||||||
SELECT
|
SELECT
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(SELECT json_agg(row_to_json(n) ORDER BY n.distance_m ASC)
|
(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,
|
) AS neighbors,
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(SELECT json_agg(row_to_json(o) ORDER BY o.overlap_m2 DESC NULLS LAST)
|
(SELECT json_agg(row_to_json(o) ORDER BY o.overlap_m2 DESC NULLS LAST)
|
||||||
FROM overlaps o),
|
FROM overlap_rows o),
|
||||||
'[]'::json
|
'[]'::json
|
||||||
) AS overlaps
|
) AS overlap_rows
|
||||||
"""),
|
"""),
|
||||||
{"wkt": geom_wkt, "our_cad": our_cad_num},
|
{"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()
|
.first()
|
||||||
)
|
)
|
||||||
neighbor_rows: list[dict[str, Any]] = list(row["neighbors"]) if row else []
|
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:
|
except Exception as e:
|
||||||
logger.warning("neighbors query failed: %s", e)
|
logger.warning("neighbors query failed: %s", e)
|
||||||
return {"data_available": False, "note": f"neighbors query failed: {e}"}
|
return {"data_available": False, "note": f"neighbors query failed: {e}"}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue