Hi all,
--
I have some questions on JSONB on PostgreSQL 9.6.
I have a table with just a single column of JSONB datatype.
The following record was inserted into the table:
INSERT INTO json_data values ( '{"id": "00043","name": "i am a boy","national_id": "SZ123123123","address": {"current": "current_address","prev":"prev_address"} ,"phone_number": "+44d765223424","dob": 123213123, "age": "87", "nationality": "british", "account_status": false, "account_type": "123", "account_balance": "123120392183091.99", "sub_account": "[00042,00043]", "days_till_next_bill": "1503513254", "photo": "bytes"} ');
I would like to update the account_balance to 1.
UPDATE json_data set "data" = jsonb_set('{"id": "00043","name": "i am a boy","national_id": "SZ123123123","address": {"current": "current_address","prev":"prev_address"} ,"phone_number": "+44d765223424","dob": 123213123, "age": "87", "nationality": "british", "account_status": false, "account_type": "123", "account_balance": "123120392183091.99", "sub_account": "[00042,00043]", "days_till_next_bill": "1503513254", "photo": "bytes"}'::jsonb, '{account_balance}', '1'::jsonb, false);
Is this the most efficient way to do it? I'm not sure because this is basically replacing the entire JSON object instead of updating a single field.
Thanks!
Regards,
Ang Wei Shan
Ang Wei Shan