My purpose is to update a jsonb column using jsonb_set, which is currently null, with an object having more than one key-value pairs. The update command executes successfully but it is not updating anything, the column is still coming up empty. I am trying the following query.
UPDATE tab
set value = jsonb_set(value, '{}', '{"a" : 100, "b" : [100, 200]}'::jsonb)
where id = 100;
Any solutions ?
From what I've understood, it appears you don't need jsonb_set for this case. Simply cast the string to jsonb for updating
UPDATE tab
set value = '{"a" : 100, "b" : [100, 200]}'::jsonb
where id = 100
--and value is null; --additional check if you need.
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With