The easiest way to explain the question is in the usage of an audit trigger.
However, on insert it saves all values, including null values. I want to filter out the null values in the
hstore(NEW.*). What is the simplest / fastest way to do this?
audit_row.row_data = hstore(NEW.*) - excluded_cols;
This obviously doesn't work but explains, hopefully, what the answer will look like.
audit_row.row_data = hstore(hstore(NEW.*) FILTER (WHERE value IS NOT NULL)) - excluded_cols;
Preference will go to answer that doesn't use an user created function, e.g. use only Postgres functions / operators.
This is for >= PostgreSQL 11.
I am looking for a solution with
jsonb. Alternative ways with
jsonb may be included, but
hstore is preferred.