I'm trying to create a log table to track changes to a table.. so I've
created a set of rules that look something like this:
CREATE RULE "m_log_change" AS ON UPDATE TO "machine"
do ( INSERT INTO machine_log (who, date, machnum, col, newval) SELECT getpgusername(), 'now'::text, old.machnum,
'host',new.host WHERE (new.host != old.host) or (old.host IS NOT NULL and new.host IS NULL) or (old.host IS NULL
andnew.host IS NOT NULL);
... more similar INSERT statements with different WHERE clauses..
);
My question is:
Is this the best way to code the WHERE? What I'm really after is "did the
value change?". I found that the tests to see if one-but-not-both of the
values is NULL are required to identify times when the value changed to or
from NULL.
Seems like a lot of extra work...
Jim Rowan DCSI DCE/DFS/Sysadmin Consulting
jmr@computing.com (512) 374-1143