Is there a way to update a JSONB value in an array of array without having to specify the index (which is not always reliable) but rather by property inside one object?
Lets say I have this JSONB value:
select '[{"foo": [{"id": "baz"}, {"id": "bar"}]}, {"foo": [{"id": "bor"}]}]'::jsonb;
I can find the element that has the id bar
with this query:
select * from x where f @> '[{"foo": [{"id": "bar"}]}]'::jsonb:
But I can't just say: Update the object where ID is bar
and change it without specifying its index:
UPDATE x SET f = jsonb_set(f, '{0,foo,1}', '{"id": "new-bar", "something": "hello"}'::jsonb);
Is there a way to update a portion of JSONB by using a property of this nested object without having to specify an index (i.e position)?
Side note: the problem with the index position is that it can vary between queries and it's not readable when reading logs.
Not sure it's clear enough, please let me know if I can improve my question!