Tuesday, 20 August 2013

postgresql triggers after update

postgresql triggers after update

The following function ,update_sessioninfo(), should only update changed
columns. The New.* columns are being updated to some incorrect values
after running:
update freeradius.radacct set acctsessiontime=25 where radacctid=3;
function
CREATE OR REPLACE FUNCTION update_sessioninfo() RETURNS trigger AS
$radacct_update$
BEGIN
-- update the updated records
update freeradius.day_guiding_usage set
acctstoptime=New.acctstoptime,acctsessiontime=New.acctsessiontime,connectinfo_start=New.connectinfo_start,connectinfo_stop=New.connectinfo_stop,acctinputoctets=New.acctinputoctets,acctoutputoctets=New.acctoutputoctets,acctterminatecause=New.acctterminatecause
where acctsessionid=Old.acctsessionid;
RETURN NULL;
END;
$radacct_update$ LANGUAGE plpgsql;
The trigger is below
CREATE TRIGGER radacct_update AFTER UPDATE ON freeradius.radacct
FOR EACH ROW
WHEN (OLD.* IS DISTINCT FROM NEW.*)
EXECUTE procedure update_sessioninfo();

No comments:

Post a Comment