[ADMIN] Some questions on PostgreSQL 9.6 JSONB - Mailing list pgsql-admin

From Wei Shan
Subject [ADMIN] Some questions on PostgreSQL 9.6 JSONB
Date
Msg-id CAFe9ZTqKPihYG6LsPqpfSmD2dK7D1jhxLTwe+7YE7x5emL-D1Q@mail.gmail.com
Whole thread Raw
Responses Re: [ADMIN] Some questions on PostgreSQL 9.6 JSONB  (Keith <keith@keithf4.com>)
List pgsql-admin
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

pgsql-admin by date:

Previous
From: Don Seiler
Date:
Subject: Re: [ADMIN] Standby Mechanics: WAL vs Streaming
Next
From: Keith
Date:
Subject: Re: [ADMIN] Some questions on PostgreSQL 9.6 JSONB