fix(geoportal): use subquery instead of JOIN for gis_cladiri_status view
LEFT JOIN caused duplicate rows and column conflicts. Replaced with a correlated subquery (LIMIT 1) to safely look up BUILD_LEGAL from the parent parcel's enrichment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,14 +47,18 @@ const VIEWS = [
|
|||||||
f."cadastralRef" AS cadastral_ref,
|
f."cadastralRef" AS cadastral_ref,
|
||||||
f."areaValue" AS area_value,
|
f."areaValue" AS area_value,
|
||||||
f."isActive" AS is_active,
|
f."isActive" AS is_active,
|
||||||
COALESCE((p.enrichment->>'BUILD_LEGAL')::int, -1) AS build_legal,
|
COALESCE(
|
||||||
f.geom
|
(SELECT (p.enrichment->>'BUILD_LEGAL')::int
|
||||||
FROM "GisFeature" f
|
FROM "GisFeature" p
|
||||||
LEFT JOIN "GisFeature" p
|
WHERE p.siruta = f.siruta
|
||||||
ON p.siruta = f.siruta
|
|
||||||
AND p."cadastralRef" = f."cadastralRef"
|
AND p."cadastralRef" = f."cadastralRef"
|
||||||
AND (p."layerId" LIKE 'TERENURI%' OR p."layerId" LIKE 'CADGEN_LAND%')
|
AND (p."layerId" LIKE 'TERENURI%' OR p."layerId" LIKE 'CADGEN_LAND%')
|
||||||
AND p.enrichment IS NOT NULL
|
AND p.enrichment IS NOT NULL
|
||||||
|
LIMIT 1),
|
||||||
|
-1
|
||||||
|
) AS build_legal,
|
||||||
|
f.geom
|
||||||
|
FROM "GisFeature" f
|
||||||
WHERE f.geom IS NOT NULL
|
WHERE f.geom IS NOT NULL
|
||||||
AND (f."layerId" LIKE 'CLADIRI%' OR f."layerId" LIKE 'CADGEN_BUILDING%')`,
|
AND (f."layerId" LIKE 'CLADIRI%' OR f."layerId" LIKE 'CADGEN_BUILDING%')`,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user