pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JSON array is not updated if updating with empty array
6+ messages / 5 participants
[nested] [flat]

* JSON array is not updated if updating with empty array
@ 2020-03-06 18:52  Radics Geza <radicsge@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Radics Geza @ 2020-03-06 18:52 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

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!

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: JSON array is not updated if updating with empty array
@ 2020-03-06 19:18  Tomas Vondra <tomas.vondra@2ndquadrant.com>
  parent: Radics Geza <radicsge@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Tomas Vondra @ 2020-03-06 19:18 UTC (permalink / raw)
  To: Radics Geza <radicsge@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: JSON array is not updated if updating with empty array
@ 2020-03-06 19:21  Radics Geza <radicsge@gmail.com>
  parent: Tomas Vondra <tomas.vondra@2ndquadrant.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Radics Geza @ 2020-03-06 19:21 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@2ndquadrant.com>; +Cc: pgsql-bugs@lists.postgresql.org

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
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: JSON array is not updated if updating with empty array
@ 2020-03-06 19:22  Jeff Janes <jeff.janes@gmail.com>
  parent: Radics Geza <radicsge@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Jeff Janes @ 2020-03-06 19:22 UTC (permalink / raw)
  To: Radics Geza <radicsge@gmail.com>; +Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>

On Fri, Mar 6, 2020 at 1:52 PM Radics Geza <radicsge@gmail.com> 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
>

Works for me.  Please show a complete working example, with CREATE TABLE,
INSER, and an UPDATE statement with legal table name and with balanced
quotes.

 Cheers,

Jeff

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: JSON array is not updated if updating with empty array
@ 2020-03-06 19:24  Christophe Pettus <xof@thebuild.com>
  parent: Radics Geza <radicsge@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Christophe Pettus @ 2020-03-06 19:24 UTC (permalink / raw)
  To: Radics Geza <radicsge@gmail.com>; +Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>; pgsql-bugs@lists.postgresql.org



> On Mar 6, 2020, at 11:21, Radics Geza <radicsge@gmail.com> wrote:
> 
> 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)

I'm still not able to reproduce it on 11.7:

xof=# create table t (j jsonb);
CREATE TABLE
xof=# insert into t values('[{"b": 1}]');
INSERT 0 1
xof=# update t set j = '[{"a": 1}]';
UPDATE 1
xof=# table t;
     j      
------------
 [{"a": 1}]
(1 row)

xof=# update t set j = '[]';
UPDATE 1
xof=# table t;
 j  
----
 []
(1 row)

--
-- Christophe Pettus
   xof@thebuild.com






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: JSON array is not updated if updating with empty array
@ 2020-03-06 19:33  Radics, Geza <radicsge@protonmail.com>
  parent: Christophe Pettus <xof@thebuild.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Radics, Geza @ 2020-03-06 19:33 UTC (permalink / raw)
  To: Christophe Pettus <xof@thebuild.com>; +Cc: Radics Geza <radicsge@gmail.com>; Tomas Vondra <tomas.vondra@2ndquadrant.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

Sorry you are right it seems one of the triggers caused an issue on my table, then please ignore.
I will check it further.

Thanks a lot for your time!



‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, March 6, 2020 7:24 PM, Christophe Pettus <xof@thebuild.com> wrote:

>
>
> > On Mar 6, 2020, at 11:21, Radics Geza radicsge@gmail.com wrote:
> > 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)
>
> I'm still not able to reproduce it on 11.7:
>
> xof=# create table t (j jsonb);
> CREATE TABLE
> xof=# insert into t values('[{"b": 1}]');
> INSERT 0 1
> xof=# update t set j = '[{"a": 1}]';
> UPDATE 1
> xof=# table t;
> j
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> [{"a": 1}]
> (1 row)
>
> xof=# update t set j = '[]';
> UPDATE 1
> xof=# table t;
> j
>
> ---------------------------------------------------------------------------
>
> []
> (1 row)
>
> -----------
>
> -- Christophe Pettus
> xof@thebuild.com







^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2020-03-06 19:33 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 18:52 JSON array is not updated if updating with empty array Radics Geza <radicsge@gmail.com>
2020-03-06 19:18 ` Tomas Vondra <tomas.vondra@2ndquadrant.com>
2020-03-06 19:21   ` Radics Geza <radicsge@gmail.com>
2020-03-06 19:24     ` Christophe Pettus <xof@thebuild.com>
2020-03-06 19:33       ` Radics, Geza <radicsge@protonmail.com>
2020-03-06 19:22 ` Jeff Janes <jeff.janes@gmail.com>

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