Postgresql - update or remove value from nested jsonb element
1 answer
You need to use the operator #-
, not -
:
SELECT jsonb '{"top": {"nested": {"leaf" : 1}}}' #- '{top,nested,leaf}';
âââââââââââââââââââââââââââ
â ?column? â
âââââââââââââââââââââââââââ¤
â {"top": {"nested": {}}} â
âââââââââââââââââââââââââââ
(1 row)
In the documentation:
-
-
(with argumenttext
): Remove key / value pair or string element from left operand. A key / value pair is matched based on their key value. -
-
(with argumentint
): remove the array element at the specified index (the number of negative integers from the end). Throws an error if the top-level container is not an array. -
#-
: remove field or element with specified path (for JSON arrays, negative integers from the end)
+8
source to share