[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [GENERAL] problem changing jsonb attribute to null value
From:       Dmitry Dolgov <9erthalion6 () gmail ! com>
Date:       2017-11-15 22:07:01
Message-ID: CA+q6zcU0ZcE1Te0xULft0kou+Xnw=Oot1humv_5i7p12aF7hKg () mail ! gmail ! com
[Download RAW message or body]

> 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?

[Attachment #3 (text/html)]

<div dir="ltr">&gt; On 15 November 2017 at 22:54, RODRIGUEZ CORTES MARIO IGNACIO \
&lt;<a href="mailto:IGNACIO.CORTES@inegi.org.mx">IGNACIO.CORTES@inegi.org.mx</a>&gt; \
wrote:<br>&gt;<br>&gt; I have a problem with a record in a jsonb type table, I&#39;m \
trying to<br>&gt; change the value of an attribute to null but it leaves me all \
the<br>&gt; content in null and not just the value<br>&gt;<br>&gt; prueba=# select \
jsonb_set(&#39;{&quot;v&quot; : 0}&#39;::jsonb, &#39;{&quot;v&quot;}&#39;, \
to_jsonb(null));<br>&gt; ERROR:   no se pudo determinar el tipo polimórfico porque \
el tipo de<br>&gt; entrada es  «unknown »<br>&gt;<br>&gt; defining null value as a \
text type:<br>&gt;<br>&gt; prueba=# select jsonb_set(&#39;{&quot;v&quot; : \
0}&#39;::jsonb, &#39;{&quot;v&quot;}&#39;,<br>&gt; to_jsonb(null::text));<br>&gt;   \
jsonb_set <br>&gt; -----------<br>&gt;   <br>&gt; (1 fila)<br>&gt;<br>&gt; it leaves \
the record in null, when I hope it leaves it with the null<br>&gt; value in attribute \
&quot;v&quot;: {&quot;v&quot;: null}<br><br><div>I think something like this should \
work:<br><br>=# select jsonb_set(&#39;{&quot;v&quot; : 0}&#39;::jsonb, \
&#39;{&quot;v&quot;}&#39;, &#39;null&#39;::jsonb);</div><div><div>   \
jsonb_set</div><div>-------------</div><div>  {&quot;v&quot;: null}</div><div>(1 \
row)</div><div><br></div></div><div>is that what you want?</div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic