ALTER TABLE node ADD COLUMN updated TIMESTAMP NOT NULL DEFAULT NOW(); CREATE OR REPLACE FUNCTION node_update_timestamp() RETURNS TRIGGER LANGUAGE PLPGSQL AS $$ BEGIN IF NEW.updated = OLD.updated THEN UPDATE node SET updated = NOW() WHERE id=NEW.id; END IF; RETURN NEW; END; $$; CREATE OR REPLACE TRIGGER node_update AFTER UPDATE ON node FOR EACH ROW EXECUTE PROCEDURE node_update_timestamp()