root/sql/sprocs/noit.metric_text_archive_log_changes.sql

Revision d50e0629228ff7ed2cbc8b9e7f375dabc526956e, 1.8 kB (checked in by Robert Treat <robert@omniti.com>, 4 years ago)

add support for checks that return null

  • Property mode set to 100644
Line 
1 -- formerly trigger function stratcon.loading_dock_metric_text_s_change_log
2
3 CREATE OR REPLACE FUNCTION noit.metric_text_archive_log_changes()
4   RETURNS trigger AS
5 $BODY$
6 DECLARE
7     v_oldvalue text;
8     v_sid integer;
9     v_name text;
10     v_value text;
11     v_whence timestamptz;
12     v_old_whence timestamptz;
13     v_old_name text;
14     v_old_sid integer;
15     v_old_value text;
16     v_max_whence timestamptz;
17 BEGIN
18
19 IF TG_OP = 'INSERT' THEN
20
21              SELECT value FROM  metric_text_changelog WHERE sid = NEW.sid AND name = NEW.name
22                  AND WHENCE = (SELECT max(whence) FROM metric_text_changelog
23                                  WHERE WHENCE <> NEW.WHENCE and sid=NEW.sid and name=NEW.name )
24                      INTO v_oldvalue;
25
26                     IF ( (NOT FOUND) OR (v_oldvalue IS DISTINCT FROM NEW.value) ) THEN
27
28                         INSERT INTO metric_text_changelog (sid,whence,name,value)
29                             VALUES (NEW.sid, NEW.whence, NEW.name, NEW.value);
30                         DELETE FROM metric_text_currently
31                                 WHERE sid = NEW.sid and name = NEW.name;
32                         INSERT INTO metric_text_currently (sid,whence,name,value)
33                                 VALUES (NEW.sid, NEW.whence, NEW.name, NEW.value);
34                     END IF;
35
36 SELECT sid,metric_name FROM metric_name_summary WHERE sid=NEW.sid  and metric_name=NEW.name
37         INTO v_sid,v_name;
38      IF NOT FOUND THEN
39           INSERT INTO  metric_name_summary(sid,metric_name,metric_type)  VALUES(NEW.sid,NEW.name,'text');
40      END IF;
41
42 ELSE
43         RAISE EXCEPTION 'Error in trigger function noit.metric_text_archive_log_changes ';
44 END IF;
45     RETURN NULL;
46 END
47 $BODY$
48   LANGUAGE 'plpgsql'  SECURITY DEFINER;
49  
50 GRANT EXECUTE ON FUNCTION noit.metric_text_archive_log_changes() TO stratcon;
51
Note: See TracBrowser for help on using the browser.