I try to create a function that adds a new pair to the object, but I get an error. I don't understand what could be the reason, explain to me stupid what's wrong here. thank you)
create or replace function add_to_json(_id int, _field text, _obj text)
returns text as
$$
begin
execute format('UPDATE public.posts SET %s = %s::jsonb || jsonb %s WHERE id = %s', _field, _field, _obj, _id);
return format('UPDATE public.posts SET %s = %s::jsonb || jsonb %s WHERE id = %s', _field, _field, _obj, _id);
end
$$
language plpgsql volatile;
select add_to_json(1, 'likes', '{"fff":123}')
ERROR: Failed to run sql query: syntax error at or near "{"