pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ivan E. Panchenko <i.panchenko@postgrespro.ru>
To: pgsql-general@lists.postgresql.org
Subject: Re: update field in jsonb
Date: Thu, 23 Nov 2017 09:06:02 +0300
Message-ID: <ae52b2f2-937d-9f4b-bb79-acb0377f991e@postgrespro.ru> (raw)
In-Reply-To: <9a1c3dd0-39f0-7da2-61b6-58621a89a288@tigernassau.com>
References: <9a1c3dd0-39f0-7da2-61b6-58621a89a288@tigernassau.com>


23.11.2017 04:45, support-tiger пишет:
> is there a way to update a single field in jsonb without replacing the 
> entire json document - couldn't find an example
>
> for example
>
> create table test (id primary key, data jsonb);
>
> insert into test ({"name":"bill", "age":29});
>
>  ?? update test   set data->age = 30
>
>
When a record in PostgeSQL is UPDATEd, its new version is created. So 
such partial JSON update would be not more than some syntax sugar. That 
is why it is not yet implemented, though plans for that exist.

Now you have to do something like:

UPDATE test SET data = jsonb_set(data, ARRAY['age'], to_jsonb(30)) WHERE ..




view thread (6+ messages)  latest in thread

Message-ID: <ae52b2f2-937d-9f4b-bb79-acb0377f991e@postgrespro.ru>
Permalink:  ../ae52b2f2-937d-9f4b-bb79-acb0377f991e@postgrespro.ru/
Also on:    postgresql.org/message-id/ae52b2f2-937d-9f4b-bb79-acb0377f991e@postgrespro.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: i.panchenko@postgrespro.ru
  Subject: Re: update field in jsonb
  In-Reply-To: <ae52b2f2-937d-9f4b-bb79-acb0377f991e@postgrespro.ru>
  References: <9a1c3dd0-39f0-7da2-61b6-58621a89a288@tigernassau.com> <ae52b2f2-937d-9f4b-bb79-acb0377f991e@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox