I want to do something that I thought was fairly simple. Produce a comma delimited list of columns that changed in an update. e.g. for a table foo:
UPDATE foo SET bar = 8, zoo = "it's a zoo in here";
Using an AFTER update trigger on foo I should then be able to loop over the table columns, comparing OLD.col with NEW.col to determine if it changed, and produce a string “bar, zoo”.
It’s easy if you hardcode the column names but that’s not an option for me. Getting the column names is easy enough, but how to dynamically get the values from NEW and OLD to compare them? Is there any way at all to do this?
You might try using
information_schemaviews to dynamically query for columns in the table. Then you could use cursor to iterate over the resultset. That could be tricky. I don’t know if cursors are supported within triggers.