Mercurial > gemma
view schema/updates/1471/01.fix-sr_in_bn_area-trigger.sql @ 5656:796196f83678
Fix check_sr_in_bn_area trigger function to only use staging_done bn.
author | Sascha Wilde <wilde@sha-bang.de> |
---|---|
date | Wed, 04 Oct 2023 18:53:55 +0200 |
parents | |
children |
line wrap: on
line source
CREATE OR REPLACE FUNCTION check_sr_in_bn_area() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN IF NOT st_intersects((SELECT area FROM waterway.bottlenecks WHERE bottleneck_id = NEW.bottleneck_id AND validity @> NEW.date_info::timestamptz AND staging_done), NEW.area) THEN RAISE EXCEPTION 'new row for relation "%" violates constraint trigger "%"', TG_TABLE_NAME, TG_NAME USING DETAIL = 'Failing row area has no intersection with bottleneck.', ERRCODE = 23514, SCHEMA = TG_TABLE_SCHEMA, TABLE = TG_TABLE_NAME, CONSTRAINT = TG_NAME; END IF; RETURN NEW; END; $$;