Get the nested object.
select jdoc -> 'members' ->'coach' from api where id = 22;
returns : {"id": 11, "name": "A dude"}
trying to update nested object, but failed.
update api set jdoc = jsonb_set(jdoc, '{members,coach,id}', 21) where id = 22;
Error:
No function matches the given name and argument types. You might need to add explicit type casts.
So where did I went wrong? jdoc column obviously is an jsonb column.
Manual reference: select jsonb_set('[{"f1":1,"f2":null},2,null,3]'::jsonb, '{0,f1}', '[2,3,4]', false)
CodePudding user response:
The third parameter needs to be a JSONB value:
jsonb_set(jdoc, '{members,coach,id}', to_jsonb(21))