Some questions on PostgreSQL 9.6 JSONB

From: Wei Shan <weishan(dot)ang(at)gmail(dot)com>
To: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Some questions on PostgreSQL 9.6 JSONB
Date: 2017-08-28 13:46:52
Message-ID: CAFe9ZTqKPihYG6LsPqpfSmD2dK7D1jhxLTwe+7YE7x5emL-D1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Keith 2017-08-28 14:06:44 Re: Some questions on PostgreSQL 9.6 JSONB
Previous Message Don Seiler 2017-08-28 13:40:27 Re: Standby Mechanics: WAL vs Streaming