Subject Re: [firebird-support] Which field was updated?
Author Helen Borrie
At 10:46 AM 1/05/2009, you wrote:
>Hi
>
>I'm creating an after update trigger and I want to know how can I retrieve the name of the field or fields that were updated. Can this be done?

"Fields" are not updated; rather, a new version of a record replaces the old one. You have no option but to go through the entire array of columns and test each one to see whether it has changed. In any trigger you can refer to OLD.AFIELDNAME and NEW.AFIELDNAME.

From v.2.1 onward,

IF (NEW.AFIELDNAME IS DISTINCT FROM OLD.AFIELDNAME) THEN...

is handy for this comparison. Prior to that, except on non-nullable columns, you must test

IF (
(NEW.AFIELDNAME <> OLD.AFIELDNAME)
OR (NEW.AFIELDNAME IS NULL AND OLD.AFIELDNAME IS NOT NULL)
OR (OLD.AFIELDNAME IS NULL AND NEW.AFIELDNAME IS NOT NULL)
) THEN...

./hb