gis
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
calcul_point_voie
Parameters
Name
Type
Mode
Definition
DECLARE nb integer; BEGIN IF TG_OP = 'DELETE' THEN SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = OLD.id_voie; UPDATE adresse.voie SET nb_point = nb WHERE id_voie = OLD.id_voie; ELSIF TG_OP = 'INSERT' THEN IF NEW.id_voie IS NOT NULL THEN SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = NEW.id_voie; UPDATE adresse.voie SET nb_point = nb WHERE id_voie = NEW.id_voie; END IF; ELSIF TG_OP = 'UPDATE' AND NEW.id_voie IS DISTINCT FROM OLD.id_voie THEN IF NEW.id_voie IS NULL THEN SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = OLD.id_voie; UPDATE adresse.voie SET nb_point = nb WHERE id_voie = OLD.id_voie; ELSIF OLD.id_voie IS NULL THEN SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = NEW.id_voie; UPDATE adresse.voie SET nb_point = nb WHERE id_voie = NEW.id_voie; ELSE SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = NEW.id_voie; UPDATE adresse.voie SET nb_point = nb WHERE id_voie = NEW.id_voie; SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = OLD.id_voie; UPDATE adresse.voie SET nb_point = nb WHERE id_voie = OLD.id_voie; END IF; END IF; RETURN NEW; END;