CREATE FUNCTION mise_a_jour_t2() RETURNS trigger AS '
BEGIN
- IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
- update table2 set champ2 = champ2 +1 where... ;
- RETURN NEW;
- ELSE IF TG_OP = 'DELETE'
- update table2 set champ2 = champ2 -1 where ... ;
- RETURN OLD ;
- END IF;
+ IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
+ UPDATE table2 SET champ2 = champ2 + 1 WHERE... ;
+ RETURN NEW;
+ ELSE IF TG_OP = 'DELETE'
+ UPDATE table2 SET champ2 = champ2 - 1 WHERE ... ;
+ RETURN OLD ;
+ END IF;
END;
' LANGUAGE plpgsql;
-CREATE TRIGGER mise_a_jour AFTER INSERT OR UPDATE OR DELETE ON table1
+CREATE TRIGGER mise_a_jour
+ AFTER INSERT OR UPDATE OR DELETE
+ ON table1
FOR EACH ROW EXECUTE PROCEDURE mise_a_jour_t2();