I'm working on a trigger, and part of its functionality is to prevent UPDATE
if the only field being updated is the timestamp
field.
My current solution is like this:
CREATE OR REPLACE FUNCTION verify() RETURNS TRIGGER AS $verify$
BEGIN
IF (TG_OP = 'UPDATE') THEN
IF ((OLD.first, OLD.middle, OLD.last, OLD.address, OLD.phone, OLD.notes)
IS DISTINCT FROM
(NEW.first, NEW.middle, NEW.last, NEW.address, NEW.phone, NEW.notes)) THEN
RETURN NEW;
ELSE
RAISE NOTICE 'Must change something besides timestamp.';
RETURN NULL;
END IF;
END IF;
RETURN NEW;
END;
$verify$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS verify ON test;
CREATE TRIGGER verify BEFORE INSERT OR UPDATE ON test
FOR EACH ROW EXECUTE PROCEDURE verify();
It works, but - if I add a field to the table, I would have to update the trigger, and that seems convoluted.
Is it possible to simplify the condition?