By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
create type t_json_val as (path text[], val jsonb);
create or replace function jsonb_mset(a jsonb, variadic b t_json_val[])
returns jsonb
immutable strict
language plpgsql
as $$
declare
bb t_json_val;
begin
foreach bb in array b loop
a := jsonb_set(a, bb.path, bb.val);
end loop;
return a;
end $$;
CREATE TYPE
CREATE FUNCTION
select jsonb_pretty(jsonb_mset('{
"food": {
"type": {
"id": 1,
"name": "good"
},
"category": {
"id": 2,
"name": "Vegetables"
},
"others": {
"descr": "It''s all good"
}
}
}',
('{food, type, name}', '"not bad"'),
('{food, category, id}', '"1"')));
jsonb_pretty |
---|
{ "food": { "type": { "id": 1, "name": "not bad" }, "others": { "descr": "It's all good" }, "category": { "id": "1", "name": "Vegetables" } } } |
SELECT 1