1 CREATE OR REPLACE FUNCTION person_aggregates_comment_count ()
6 IF (was_restored_or_created (TG_OP, OLD, NEW)) THEN
10 comment_count = comment_count + 1
12 person_id = NEW.creator_id;
13 ELSIF (was_removed_or_deleted (TG_OP, OLD, NEW)) THEN
17 comment_count = comment_count - 1
19 person_id = OLD.creator_id;
25 CREATE OR REPLACE FUNCTION person_aggregates_post_count ()
30 IF (was_restored_or_created (TG_OP, OLD, NEW)) THEN
34 post_count = post_count + 1
36 person_id = NEW.creator_id;
37 ELSIF (was_removed_or_deleted (TG_OP, OLD, NEW)) THEN
41 post_count = post_count - 1
43 person_id = OLD.creator_id;
49 CREATE OR REPLACE FUNCTION community_aggregates_comment_count ()
54 IF (was_restored_or_created (TG_OP, OLD, NEW)) THEN
56 community_aggregates ca
58 comments = comments + 1
63 AND ca.community_id = p.community_id;
64 ELSIF (was_removed_or_deleted (TG_OP, OLD, NEW)) THEN
66 community_aggregates ca
68 comments = comments - 1
73 AND ca.community_id = p.community_id;