Postgres' hstore extension has a neat subtraction operator:
hstore - text[]
hstore - hstore
In the first case, it removes the key/value pairs where the keys are found in the array of strings: in the second case it removes all matching key/value pairs from the first hstore that appear in the second hstore.
It seems this operator does not exist for the new jsonb data type. Is there a simple way to perform these tasks?
The key is the
json_each()function, and the ability in PostgreSQL to manually build up a json value.Here is a function which can handle
json - text[]:To handle the
json - jsoncase, you simple need to change theWHEREclause: