diff --git a/db/sql/deploy/buildings_reference/functions/suburb_locality.sql b/db/sql/deploy/buildings_reference/functions/suburb_locality.sql index 57f6f783..31e79df4 100644 --- a/db/sql/deploy/buildings_reference/functions/suburb_locality.sql +++ b/db/sql/deploy/buildings_reference/functions/suburb_locality.sql @@ -140,11 +140,15 @@ COMMENT ON FUNCTION buildings_reference.suburb_locality_attribute_update_buildin CREATE OR REPLACE FUNCTION buildings_reference.suburb_locality_geometry_update_building_outlines(varchar) RETURNS integer AS $$ - UPDATE buildings.building_outlines - SET suburb_locality_id = buildings_reference.suburb_locality_intersect_polygon(shape), + WITH sub_tas AS ( + SELECT ST_Subdivide(ST_SetSRID(ST_GeometryFromText($1), 2193)) AS shape + ) + UPDATE buildings.building_outlines bo + SET suburb_locality_id = buildings_reference.suburb_locality_intersect_polygon(bo.shape), last_modified = NOW() - WHERE ST_Intersects(shape, ST_SetSRID(ST_GeometryFromText($1), 2193)) - AND suburb_locality_id != buildings_reference.suburb_locality_intersect_polygon(shape) + FROM sub_tas ta + WHERE ST_Intersects(bo.shape, ta.shape) + AND suburb_locality_id != buildings_reference.suburb_locality_intersect_polygon(bo.shape) RETURNING building_outline_id; $$ LANGUAGE sql VOLATILE; diff --git a/db/sql/deploy/buildings_reference/functions/territorial_authority.sql b/db/sql/deploy/buildings_reference/functions/territorial_authority.sql index 09475f35..c54342e8 100644 --- a/db/sql/deploy/buildings_reference/functions/territorial_authority.sql +++ b/db/sql/deploy/buildings_reference/functions/territorial_authority.sql @@ -171,12 +171,16 @@ COMMENT ON FUNCTION buildings_reference.territorial_authority_attribute_update_b CREATE OR REPLACE FUNCTION buildings_reference.territorial_authority_geometry_update_building_outlines(varchar) RETURNS integer AS $$ - UPDATE buildings.building_outlines - SET territorial_authority_id = buildings_reference.territorial_authority_grid_intersect_polygon(shape), - last_modified = NOW() - WHERE ST_Intersects(shape, ST_SetSRID(ST_GeometryFromText($1), 2193)) - AND territorial_authority_id != buildings_reference.territorial_authority_grid_intersect_polygon(shape) - RETURNING building_outline_id; + WITH sub_tas AS ( + SELECT ST_Subdivide(ST_SetSRID(ST_GeometryFromText($1), 2193)) AS shape + ) + UPDATE buildings.building_outlines bo + SET territorial_authority_id = buildings_reference.territorial_authority_grid_intersect_polygon(bo.shape), + last_modified = NOW() + FROM sub_tas ta + WHERE ST_Intersects(bo.shape, ta.shape) + AND territorial_authority_id != buildings_reference.territorial_authority_grid_intersect_polygon(bo.shape) + RETURNING building_outline_id; $$ LANGUAGE sql VOLATILE;