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

Поиск
Список
Период
Сортировка
От Radics Geza
Тема Re: JSON array is not updated if updating with empty array
Дата
Msg-id CAJFbfO_vv_Zdsd9hQ5qNpVD6m2a20d0jdVgqA=XSdG_evcpH0A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: JSON array is not updated if updating with empty array  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
Ответы Re: JSON array is not updated if updating with empty array  (Christophe Pettus <xof@thebuild.com>)
Список pgsql-bugs
I should have written that the precondition is that the column should contains a non-empty json array before the update as in the example.
(The insert works, the update also works if the previous content was not an array before e.g. null or '{}' but not as above)

On Fri, Mar 6, 2020 at 7:18 PM Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote:
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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: JSON array is not updated if updating with empty array
Следующее
От: Jeff Janes
Дата:
Сообщение: Re: JSON array is not updated if updating with empty array