On some occasion I'd like before UPDATE
to make sure which columns are changed. To make it as generic as possible, I don't want to use schema, table or column names in function. I found some solution here in SO and other places, and particularly liked idea to use hstore
from this answer
Downside of hstore
, as said widely, is it that this way I lose data types, everything is stringified.
But using it in context of trigger (while having no complex cols like json
or hstore
), where both NEW
and OLD
have same set of cols with according datatypes, I could think of just one problem: NULL and empty values will be not distinguishable.
What other problems I may be faced with, when I detect changes in trigger function like this:
changes := hstore(NEW) - hstore(OLD);
Alternative seems to use jsonb
and then write some jsonb_diff
function to discover changes. hstore
's offered internal subtract-operation seems way more robust, but maybe I have not considered all weak points there.
I'm using Postgres 9.6.