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

List:       postgresql-general
Subject:    Re: a bug jsonb?
From:       Josef Šimánek <josef.simanek () gmail ! com>
Date:       2018-11-22 15:26:10
Message-ID: CAFp7QwoBLLKNFJETuPLENMOV1Z=b3qykg-bb15oWLmBGkfHoDw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


the order is changed as well on your screenshot
čt 22. 11. 2018 v 16:23 odesílatel Станислав Губанов <gubanovss@gmail.com>
napsal:

> I think yes.
> Please look at this screen shot
> order of key in json not changed in pgAdmin, maybe exists some option for
> turn on/off this feature.
>
> [image: image.png]
>
> чт, 22 нояб. 2018 г. в 18:04, Josef  imánek <josef.simanek@gmail.com>:
>
>> If I understand well your question, this is expected with JSONB.
>>
>> see https://www.postgresql.org/docs/current/datatype-json.html for more
>> info:
>>
>> ...jsonb does not preserve white space, does not preserve the order of
>> object keys, and does not keep duplicate object keys. If duplicate keys are
>> specified in the input, only the last value is kept...
>>
>> čt 22. 11. 2018 v 15:59 odesílatel Станислав Губанов <gubanovss@gmail.com>
>> napsal:
>>
>>> Hello!
>>>
>>> I'd like to clarify, if this a bug or a feature
>>>
>>> simple JSON
>>> {"rootC":{},"rootB":{},"rootZ":{},"rootA":[]}
>>>
>>> Table for data
>>> create table test_json (json_data jsonb);
>>>
>>> put json into table
>>> INSERT INTO test_json (json_data) VALUES
>>> ('{"rootC":{},"rootB":{},"rootZ":{},"rootA":[]}');
>>>
>>> order of key in json is changed in such query:
>>> SELECT json_data FROM test_json;
>>> expected result: {"rootC":{},"rootB":{},"rootZ":{},"rootA":[]}
>>> actual result: {"rootA": [], "rootB": {}, "rootC": {}, "rootZ": {}}
>>>
>>> ----- console log -----
>>> test=# create table test_json (json_data jsonb);
>>> CREATE TABLE
>>> test=# INSERT INTO test_json (json_data) VALUES
>>> ('{"rootC":{},"rootB":{},"rootZ":{},"rootA":[]}');
>>> INSERT 0 1
>>> test=# select json_data from test_json;
>>>                       json_data
>>> ------------------------------------------------------
>>>  {"rootA": [], "rootB": {}, "rootC": {}, "rootZ": {}}
>>> (1 row)
>>>
>>> test=# drop table test_json;
>>> DROP TABLE
>>>
>>> --
>>> Sincerely, Stanislav!
>>>
>>
>
> --
> С уважением, Станислав!
>

[Attachment #5 (text/html)]

<div dir="ltr">the order is changed as well on your screenshot<br><div \
class="gmail_quote"><div dir="ltr">čt 22. 11. 2018 v  16:23 odesílatel \
Станислав Губанов &lt;<a \
href="mailto:gubanovss@gmail.com">gubanovss@gmail.com</a>&gt; \
napsal:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think \
yes.<div>Please look at this screen shot</div><div>order of key in json not changed \
in pgAdmin, maybe exists some option for turn on/off this \
feature.<br></div><div><br></div><div><div><div><img src="cid:ii_josqtufr1" \
alt="image.png" width="562" height="310"><br></div></div></div></div><br><div \
class="gmail_quote"><div dir="ltr">чт, 22 нояб. 2018 г. в 18:04, Josef  \
imánek &lt;<a href="mailto:josef.simanek@gmail.com" \
target="_blank">josef.simanek@gmail.com</a>&gt;:<br></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">If I understand well your \
question, this is expected with JSONB.<div><br></div><div>see  <a \
href="https://www.postgresql.org/docs/current/datatype-json.html" \
target="_blank">https://www.postgresql.org/docs/current/datatype-json.html</a> for \
more info:<br><br>...jsonb does not preserve white space, does not preserve the order \
of object keys, and does not keep duplicate object keys. If duplicate keys are \
specified in the input, only the last value is kept...<br></div></div></div><br><div \
class="gmail_quote"><div dir="ltr">čt 22. 11. 2018 v  15:59 odesílatel \
Станислав Губанов &lt;<a href="mailto:gubanovss@gmail.com" \
target="_blank">gubanovss@gmail.com</a>&gt; napsal:<br></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div dir="ltr">Hello!<div><br></div><div>I&#39;d like to clarify, if this a \
bug or a feature</div><div><br></div><div>simple JSON  \
</div><div>{&quot;rootC&quot;:{},&quot;rootB&quot;:{},&quot;rootZ&quot;:{},&quot;rootA&quot;:[]}<br></div><div><br></div><div>Table \
for data</div><div>create table test_json (json_data jsonb);  \
</div><div><br></div><div>put json into table  <br></div><div>INSERT INTO test_json \
(json_data) VALUES (&#39;{&quot;rootC&quot;:{},&quot;rootB&quot;:{},&quot;rootZ&quot;:{},&quot;rootA&quot;:[]}&#39;);<br></div><div><br></div><div>order \
of key in json is changed in such query:</div><div>SELECT json_data FROM \
test_json;</div><div><div>expected result: \
{&quot;rootC&quot;:{},&quot;rootB&quot;:{},&quot;rootZ&quot;:{},&quot;rootA&quot;:[]}</div><div>actual \
result: {&quot;rootA&quot;: [], &quot;rootB&quot;: {}, &quot;rootC&quot;: {}, \
&quot;rootZ&quot;: {}}</div></div><div><br></div><div>----- console log -----  \
<br></div><div>test=# create table test_json (json_data \
jsonb);<br></div><div><div>CREATE TABLE</div><div>test=# INSERT INTO test_json \
(json_data) VALUES (&#39;{&quot;rootC&quot;:{},&quot;rootB&quot;:{},&quot;rootZ&quot;:{},&quot;rootA&quot;:[]}&#39;);</div><div>INSERT \
0 1</div><div>test=# select json_data from test_json;</div><div>                      \
json_data</div><div>------------------------------------------------------</div><div> \
{&quot;rootA&quot;: [], &quot;rootB&quot;: {}, &quot;rootC&quot;: {}, \
&quot;rootZ&quot;: {}}</div><div>(1 row)</div><div><br></div><div>test=# drop table \
test_json;</div><div>DROP TABLE</div><div><br></div>-- <br><div dir="ltr" \
class="m_-2893091152027756976m_8534984404878019759m_-1952751310584570622gmail_signature">Sincerely, \
Stanislav!</div></div></div></div></div></div></div></div></div></div></div></div> \
</blockquote></div> </blockquote></div><br clear="all"><div><br></div>-- <br><div \
dir="ltr" class="m_-2893091152027756976gmail_signature" \
data-smartmail="gmail_signature">С уважением, Станислав!</div> \
</blockquote></div></div>

--00000000000080b694057b427d34--


["image.png" (image/png)]

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

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