Use a Postgres trigger to record the JSON of only the modified fields
问题 Is there a way to get the JSON of the only modified fields? Now I use the following trigger but the entire line is printed in the changelog. Example tables: TABLE tbl_changelog ( tbl TEXT, op TEXT, new JSON, old JSON ); TABLE tbl_items ( f1 TEXT, f2 TEXT ); Trigger: CREATE OR REPLACE FUNCTION changelog_procedure() RETURNS trigger AS $$ BEGIN INSERT INTO tbl_changelog(tbl, op, new, old) VALUES (TG_TABLE_NAME, TG_OP, row_to_json(NEW), row_to_json(OLD)); RETURN NULL; END; $$ LANGUAGE plpgsql