Answer the question
In order to leave comments, you need to log in
How to change value in JSONB?
I have a table that has a data field that is in JSONB format. This field has the following structure:
{"requisites":
{"kpp": "212997417444",
"ogrn":
{"number": "219322571340"}}
I need to change the value for the kpp field. I'm trying to do it like this:
update 'table name' set data = jsonb_set(data, '{requisites}', '{"kpp": 777}') where 'something';
But at the same time, everything else (for example, ogrn) is simply erased, and I need to save it and change only kpp. Tell me, please, what am I doing wrong? Thanks in advance!
Answer the question
In order to leave comments, you need to log in
You must specify the full path.
select jsonb_value,
jsonb_set(jsonb_value, '{requisites,kpp}', '"777"', false)
FROM test;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question