pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Radics Geza <radicsge@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: JSON array is not updated if updating with empty array
Date: Fri, 6 Mar 2020 20:18:14 +0100
Message-ID: <20200306191814.5fioiqy6ahxv6i7n@development> (raw)
In-Reply-To: <CAJFbfO84H34Fqyxgk2S8erN+FarooDeKS+vMM1dvvs9gPkq5oA@mail.gmail.com>
References: <CAJFbfO84H34Fqyxgk2S8erN+FarooDeKS+vMM1dvvs9gPkq5oA@mail.gmail.com>

On Fri, Mar 06, 2020 at 06:52:43PM +0000, Radics Geza wrote:
>Json column is not updated if the update is an empty array '[]'.
>
>UPDATE table SET "jsonbcol" = '[{"a":1}]';
>UPDATE table SET "jsonbcol = '[]' RETURNING "jsonbcol";
>
>jsonbcol
>------------
> [{"a": 1}]
>(1 row)
>
>It worked in postgres 9.6, but not in 11.7 / 12.2
>
>thanks!

I can't reproduce this (I've tried on 12.2 and 13devel):

test=# create table t (x jsonb);
CREATE TABLE
test=# insert into t values ('[]');
INSERT 0 1
test=# select * from t;
  x
----
  []
(1 row)

test=# UPDATE t SET "x" = '[{"a":1}]';
UPDATE 1
test=# select * from t;
      x
------------
  [{"a": 1}]
(1 row)

test=# UPDATE t SET "x" = '[]';
UPDATE 1
test=# select * from t;
  x
----
  []
(1 row)

ISTM you have a typo in the second query - you're missing the closing "
after the column name, so the command is not really complete/executed.


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





view thread (6+ messages)  latest in thread

Message-ID: <20200306191814.5fioiqy6ahxv6i7n@development>
Permalink:  ../20200306191814.5fioiqy6ahxv6i7n@development/
Also on:    postgresql.org/message-id/20200306191814.5fioiqy6ahxv6i7n@development

 · 

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-bugs@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com, radicsge@gmail.com
  Subject: Re: JSON array is not updated if updating with empty array
  In-Reply-To: <20200306191814.5fioiqy6ahxv6i7n@development>
  References: <CAJFbfO84H34Fqyxgk2S8erN+FarooDeKS+vMM1dvvs9gPkq5oA@mail.gmail.com> <20200306191814.5fioiqy6ahxv6i7n@development>

* 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