Monday, December 24, 2007

How to detect if field's value changes in UPDATE trigger

use this approach if your field is NOT NULLable:

if NEW.field <> OLD.field then
raise notice 'something changes';
end if;





use this approach if your field is NULLable: # is the XOR of Postgres



false xor false = false
false xor true = true
true xor false = true
true xor true = false


if

( (NEW.field is null)::int # (OLD.field is null)::int ) = 1


OR

NEW.field <> OLD.field

then

raise notice 'something changes';

end if;

0 Comments:

Post a Comment

<< Home