replacing jsonb field value

From: "john(dot)tiger" <john(dot)tigernassau(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: replacing jsonb field value
Date: 2015-05-30 02:52:58
Message-ID: 5569260A.4080407@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

using 9.4.2

suppose we have
create table test (id serial primary key, data jsonb);
insert into test (data) values ({"a":1, "b":2})

want to replace "b" with 3

okay, we are retrieving entire record
res = select * from test where data ->> b = 2

newrec = res
newrec["b" = 3

delete from test where data ->> b= 2
insert into test (data) values (newrec)

is this the best way until upsert arrives ?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Haas 2015-05-30 03:08:44 Re: [HACKERS] Re: 9.4.1 -> 9.4.2 problem: could not access status of transaction 1
Previous Message Daniel Begin 2015-05-30 02:19:03 Re: Planner cost adjustments