fn jsonb_set4(
target: JsonbRef<'_>,
path: ListRef<'_>,
new_value: JsonbRef<'_>,
create_if_missing: bool,
) -> Result<JsonbVal>
Expand description
Returns target
with the item designated by path
replaced by new_value
, or with new_value
added if create_if_missing
is true (which is the default) and the item designated by path does
not exist. All earlier steps in the path must exist, or the target
is returned unchanged. As
with the path oriented operators, negative integers that appear in the path count from the end
of JSON arrays.
If the last path step is an array index that is out of range, and create_if_missing
is true,
the new value is added at the beginning of the array if the index is negative, or at the end of
the array if it is positive.
ยงExamples
query T
SELECT jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0,f1}', '[2,3,4]', false);
----
[{"f1": [2, 3, 4], "f2": null}, 2, null, 3]
query T
SELECT jsonb_set('[{"f1":1,"f2":null},2]', '{0,f3}', '[2,3,4]');
----
[{"f1": 1, "f2": null, "f3": [2, 3, 4]}, 2]