tww
.tww_app
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
symbology_on_reach_delete()
Parameters
Name
Type
Mode
IN
Definition
DECLARE channel_id text; reach_count integer; BEGIN -- get channel obj_id SELECT fk_wastewater_structure INTO channel_id FROM tww_od.wastewater_networkelement WHERE wastewater_networkelement.obj_id = OLD.obj_id; DELETE FROM tww_od.wastewater_networkelement WHERE obj_id = OLD.obj_id; DELETE FROM tww_od.reach_point WHERE obj_id = OLD.fk_reach_point_from; DELETE FROM tww_od.reach_point WHERE obj_id = OLD.fk_reach_point_to; -- delete channel if no reach left SELECT COUNT(fk_wastewater_structure) INTO reach_count FROM tww_od.wastewater_networkelement WHERE fk_wastewater_structure = channel_id; IF reach_count = 0 THEN RAISE NOTICE 'Removing channel (%) since no reach is left', channel_id; DELETE FROM tww_od.channel WHERE obj_id = channel_id; DELETE FROM tww_od.wastewater_structure WHERE obj_id = channel_id; END IF; RETURN NEW; END;