The *hstore* type in Postgres provides an [operation to calculate the set difference](https://www.postgresql.org/docs/14/hstore.html#HSTORE-OP-TABLE) (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.
Asked by jo-so
(71 rep)
Mar 15, 2022, 09:49 PM
Last activity: Mar 27, 2025, 08:20 PM
Last activity: Mar 27, 2025, 08:20 PM