pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedproblem changing jsonb attribute to null value
2+ messages / 2 participants
[nested] [flat]
* problem changing jsonb attribute to null value
@ 2017-11-15 21:54 RODRIGUEZ CORTES MARIO IGNACIO <IGNACIO.CORTES@inegi.org.mx>
2017-11-15 22:07 ` Re: problem changing jsonb attribute to null value Dmitry Dolgov <9erthalion6@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: RODRIGUEZ CORTES MARIO IGNACIO @ 2017-11-15 21:54 UTC (permalink / raw)
To: pgsql-general
Hello:
I have a problem with a record in a jsonb type table, I'm trying to
change the value of an attribute to null but it leaves me all the
content in null and not just the value, I show you an example first of
how to define the null attribute:
prueba=# select jsonb_build_object('v', null);
jsonb_build_object
--------------------
{"v": null}
(1 fila)
this jsonb record is correct, then when trying to change the value with
jsonb_set with some value of type jsonb, it does it correctly:
prueba=# select jsonb_set('{"v" : 0}'::jsonb, '{"v"}', to_jsonb(1));
jsonb_set
-----------
{"v": 1}
(1 fila)
but if i try to put the null value in "v" attribute, apparently is not
allowed:
prueba=# select jsonb_set('{"v" : 0}'::jsonb, '{"v"}', to_jsonb(null));
ERROR: no se pudo determinar el tipo polimórfico porque el tipo de
entrada es «unknown»
defining null value as a text type:
prueba=# select jsonb_set('{"v" : 0}'::jsonb, '{"v"}',
to_jsonb(null::text));
jsonb_set
-----------
(1 fila)
it leaves the record in null, when I hope it leaves it with the null
value in attribute "v": {"v": null}
thank you for your help!!!!
Regards!!!!
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: problem changing jsonb attribute to null value
2017-11-15 21:54 problem changing jsonb attribute to null value RODRIGUEZ CORTES MARIO IGNACIO <IGNACIO.CORTES@inegi.org.mx>
@ 2017-11-15 22:07 ` Dmitry Dolgov <9erthalion6@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Dolgov @ 2017-11-15 22:07 UTC (permalink / raw)
To: RODRIGUEZ CORTES MARIO IGNACIO <IGNACIO.CORTES@inegi.org.mx>; +Cc: pgsql-general
> On 15 November 2017 at 22:54, RODRIGUEZ CORTES MARIO IGNACIO <
IGNACIO.CORTES@inegi.org.mx> wrote:
>
> I have a problem with a record in a jsonb type table, I'm trying to
> change the value of an attribute to null but it leaves me all the
> content in null and not just the value
>
> prueba=# select jsonb_set('{"v" : 0}'::jsonb, '{"v"}', to_jsonb(null));
> ERROR: no se pudo determinar el tipo polimórfico porque el tipo de
> entrada es «unknown»
>
> defining null value as a text type:
>
> prueba=# select jsonb_set('{"v" : 0}'::jsonb, '{"v"}',
> to_jsonb(null::text));
> jsonb_set
> -----------
>
> (1 fila)
>
> it leaves the record in null, when I hope it leaves it with the null
> value in attribute "v": {"v": null}
I think something like this should work:
=# select jsonb_set('{"v" : 0}'::jsonb, '{"v"}', 'null'::jsonb);
jsonb_set
-------------
{"v": null}
(1 row)
is that what you want?
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2017-11-15 22:07 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-15 21:54 problem changing jsonb attribute to null value RODRIGUEZ CORTES MARIO IGNACIO <IGNACIO.CORTES@inegi.org.mx>
2017-11-15 22:07 ` Dmitry Dolgov <9erthalion6@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