Re: JSON array is not updated if updating with empty array

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: Radics Geza <radicsge(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: JSON array is not updated if updating with empty array
Date: 2020-03-06 19:18:14
Message-ID: 20200306191814.5fioiqy6ahxv6i7n@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Radics Geza 2020-03-06 19:21:27 Re: JSON array is not updated if updating with empty array
Previous Message Jeff Janes 2020-03-06 19:09:13 Re: BUG #16287: 'Server doesn't listen' after setting 'timezone' to "America/Detroit US/Michigan"