Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.postgresql > #810

Re: Update Json column

X-Received by 10.200.82.5 with SMTP id r5mr13349602qtn.58.1519816890626; Wed, 28 Feb 2018 03:21:30 -0800 (PST)
X-Received by 10.31.48.198 with SMTP id w189mr1868752vkw.1.1519816890330; Wed, 28 Feb 2018 03:21:30 -0800 (PST)
Path csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!t24no900670qtn.0!news-out.google.com!o9ni256qte.1!nntp.google.com!t24no900666qtn.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.databases.postgresql
Date Wed, 28 Feb 2018 03:21:30 -0800 (PST)
In-Reply-To <p73l09$27o$1@dont-email.me>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=5.238.230.49; posting-account=AVfdWQoAAAB6NsIEvw9Dr_Zj2mt265Gj
NNTP-Posting-Host 5.238.230.49
References <fd35c1ca-2d97-476e-88bd-36c0dd722b41@googlegroups.com> <p73l09$27o$1@dont-email.me>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <c9fb27ea-edc5-44db-8bb4-92b262192d47@googlegroups.com> (permalink)
Subject Re: Update Json column
From forough m <fmirkarimzade@gmail.com>
Injection-Date Wed, 28 Feb 2018 11:21:30 +0000
Content-Type text/plain; charset="UTF-8"
Lines 37
Xref csiph.com comp.databases.postgresql:810

Show key headers only | View raw


On Tuesday, February 27, 2018 at 4:34:10 PM UTC+3:30, Laurenz Albe wrote:
> forough m wrote:
> 
> > I create a table with a Json type column. I need to update one key:value
> > in Json. i.e increment value of 3 to 5. Can i do it?
> 
> If you have PostgreSQL 9.5 or better, you can use "json_set" like this:
> 
> CREATE TABLE jsontest (
>    id integer PRIMARY KEY,
>    j jsonb
> );
> 
> INSERT INTO jsontest VALUES (1, '{"a": 12, "b": {"c": 12, "d": 4}}');
> 
> TABLE jsontest;
> 
>  id |                 j                 
> ----+-----------------------------------
>   1 | {"a": 12, "b": {"c": 12, "d": 4}}
> (1 row)
> 
> UPDATE jsontest
>    SET j = jsonb_set(
>               j,
>               '{b,c}',
>               ((j #>> '{b,c}')::integer + 30)::text::jsonb
>            )
>    WHERE id = 1;
> 
> TABLE jsontest;
> 
>  id |                 j                 
> ----+-----------------------------------
>   1 | {"a": 12, "b": {"c": 42, "d": 4}}
> (1 row)

Sorry. I test it but it has no result. SQL query executed without any error but value in Json not changed.

Back to comp.databases.postgresql | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Update Json column forough m <fmirkarimzade@gmail.com> - 2018-02-26 22:09 -0800
  Re: Update Json column Laurenz Albe <laurenz@nospam.pn> - 2018-02-27 13:04 +0000
    Re: Update Json column forough m <fmirkarimzade@gmail.com> - 2018-02-28 03:06 -0800
    Re: Update Json column forough m <fmirkarimzade@gmail.com> - 2018-02-28 03:21 -0800
      Re: Update Json column Laurenz Albe <laurenz@nospam.pn> - 2018-03-01 10:18 +0000
        Re: Update Json column forough m <fmirkarimzade@gmail.com> - 2018-03-05 01:44 -0800
          Re: Update Json column forough m <fmirkarimzade@gmail.com> - 2018-03-06 07:47 -0800
            Re: Update Json column Laurenz Albe <laurenz@nospam.pn> - 2018-03-07 07:48 +0000
              Re: Update Json column forough m <fmirkarimzade@gmail.com> - 2018-03-07 00:09 -0800
                Re: Update Json column Laurenz Albe <laurenz@nospam.pn> - 2018-03-08 11:36 +0000
                Re: Update Json column forough m <fmirkarimzade@gmail.com> - 2018-03-09 21:07 -0800
              Re: Update Json column forough m <fmirkarimzade@gmail.com> - 2018-03-07 00:10 -0800

csiph-web