Remove multiple keys from jsonb column in one statement
Or the minus operator once (but using a text array):
SELECT '{ "a": 1, "b": 2, "c": 3 }'::jsonb - '{a,b}'::text[];
?column?
----------
{"c": 3}
(1 row)
If you need to remove multiple non-nested keys you can use -
operator:
SELECT '{ "a": 1, "b": 2, "c": 3 }'::jsonb - ARRAY['a', 'b'];
That should be as simple as applying the #-
operator multiple times:
SELECT '{ "a": 1, "b": 2, "c": 3 }'::jsonb #- '{a}' #- '{b}';
?column?
----------
{"c": 3}
(1 row)