Hello everybody. Writing a trigger on plpgsql, I am trying to loop through the old and new values of each column in the table. The problem is that I don’t know how to correctly use this variable in an expression like OLD.current_column_name and NEW.current_column_name .
CREATE FUNCTION my_function() RETURNS TRIGGER AS $emp_stamp$ DECLARE current_column_name text; BEGIN FOR current_column_name IN SELECT column_name FROM information_schema.Columns WHERE table_schema = TG_TABLE_SCHEMA AND table_name = TG_TABLE_NAME LOOP IF (OLD."current_column_name" <> NEW."current_column_name") then ... END IF; END LOOP; RETURN NEW; END; $emp_stamp$ LANGUAGE plpgsql; CREATE TRIGGER my_trigger AFTER UPDATE ON my_table FOR EACH ROW EXECUTE PROCEDURE my_function(); I get the following error: ERROR: record "old" has no field "current_column_name" I tried to experiment with quotes in different ways, but nothing happened. As a result, I need to write the changed values from the table in the following form: column_name , old_value and new_value . Tell me, please, how to do it correctly.