The hstore type in Postgres provides an operation to calculate the set difference (EXCEPT) of two records. Is there something similar for jsonb? The best I've got is SELECT * FROM jsonb_each('{"a":1, "b":2}'::jsonb) EXCEPT SELECT * FROM jsonb_each('{"a":1}'::jsonb)
, but I don't know how to convert it back to jsonb.
I want to use this to calculate the difference (the changed values) between OLD
and NEW
in a trigger.
jsonb - jsonb
. Thanks for the confirmation.