view schema/updates/1426/01.historicise_axis.sql @ 5559:ce9a9a1bf92f

Make invalid output of ISRSrange_area() less likely, next try Since ST_MakeValid() might return a collection of lower-to-equal dimension geometries, distill only the polygons from it. This should prevent respective errors when trying to save the result to a column of type MultiPolygon.
author Tom Gottfried <tom@intevation.de>
date Thu, 02 Dec 2021 12:37:33 +0100
parents e8661379a6c5
children
line wrap: on
line source

ALTER TABLE waterway.waterway_axis
    ADD validity tstzrange NOT NULL DEFAULT tstzrange(current_timestamp, NULL)
        CHECK (NOT isempty(validity)),
    ADD last_found timestamp with time zone NOT NULL DEFAULT current_timestamp;

-- Assume existing entries have been valid since last successful import
UPDATE waterway.waterway_axis SET validity = tstzrange(
    (SELECT max(changed) FROM import.imports
        WHERE kind = 'wx' AND state = CAST('accepted' AS import_state)),
    NULL);

DROP TRIGGER waterway_axis_wtwaxs_unique ON waterway.waterway_axis;
CREATE CONSTRAINT TRIGGER waterway_axis_wtwaxs_unique
    AFTER INSERT OR UPDATE OF wtwaxs, validity ON waterway.waterway_axis
    FOR EACH ROW EXECUTE FUNCTION prevent_st_equals('wtwaxs', 'validity');

CREATE INDEX waterway_axis_validity
    ON waterway.waterway_axis USING GiST (validity);

-- No more need to delete
DROP POLICY responsibility_area_delete ON waterway.waterway_axis;