From fbb76812f478b0d11ff7ff24e0dbb80d4189ba01 Mon Sep 17 00:00:00 2001 From: lekss361 Date: Sat, 16 May 2026 18:29:35 +0300 Subject: [PATCH] fix(recommend): cad_buildings.floors is INTEGER, not TEXT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROD 500 on /api/v1/analytics/recommend/mix: psycopg.errors.UndefinedFunction: operator does not exist: integer ~ unknown LINE 19: AND ((cb.floors ~ '^[0-9]+$' AND cb.f... _district_cadastre_baseline use regex \ on cb.floors. Schema is INTEGER (verified information_schema), so the regex defence against text values ('1-2', '2-3' etc) is misplaced — simplify to floors >= 3 with NULL safety via OR purpose ILIKE '%многокв%' fallback. --- backend/app/services/analytics_queries.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/app/services/analytics_queries.py b/backend/app/services/analytics_queries.py index e80ca003..0b3855df 100644 --- a/backend/app/services/analytics_queries.py +++ b/backend/app/services/analytics_queries.py @@ -1349,10 +1349,9 @@ def _district_cadastre_baseline(db: Session, *, district_name: str) -> dict[str, WHERE cb.cost_value IS NOT NULL AND cb.area IS NOT NULL AND cb.area >= 100 - -- floors хранится как TEXT (встречаются '1-2', '2-3') — - -- считаем только чистые числа ≥3, либо purpose-fallback. - AND ((cb.floors ~ '^[0-9]+$' AND cb.floors::int >= 3) - OR cb.purpose ILIKE '%многокв%') + -- floors INTEGER (Rosreestr ETL приводит к int); NULL = unknown. + -- Считаем МКД если floors ≥3 или purpose содержит «многокв». + AND (cb.floors >= 3 OR cb.purpose ILIKE '%многокв%') AND (cb.cost_value / NULLIF(cb.area, 0)) BETWEEN 5000 AND 500000 ) -- 2.45.3