From: | Bryn Llewellyn <bryn(at)yugabyte(dot)com> |
---|---|
To: | pgsql-hackers list <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | jsonb_object() seems to be buggy. jsonb_build_object() is good. |
Date: | 2020-02-15 02:21:54 |
Message-ID: | E1529841-8E71-4CA1-8B75-95527086D820@yugabyte.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Execute this:
select jsonb_pretty(jsonb_build_object(
'a'::varchar, 1.7::numeric,
'b'::varchar, 'dog'::varchar,
'c'::varchar, true::boolean
))
It produces the result that I expect:
{ +
"a": 1.7, +
"b": "dog",+
"c": true +
}
Notice that the numeric, text, and boolean primitive values are properly rendered with the text value double-quoted and the numeric and boolean values unquoted.
Now execute this supposed functional equivalent:
select jsonb_pretty(jsonb_object(
'{a, 17, b, "dog", c, true}'::varchar[]
))
It is meant to be a nice alternative when you want to build an object (rather than an array) because the syntax is less verbose.
However, it gets the wrong answer, thus:
{ +
"a": "17", +
"b": "dog",+
"c": "true"+
}
Now, the numeric value and the boolean value are double-quoted—in other words, they have been implicitly converted to JSON primitive text values.
Do you agree that this is a bug?
Notice that I see this behavior in vanilla PostgreSQL 11.2 and in YugabyteDB Version 2.0.11.0. See this blogpost:
“Distributed PostgreSQL on a Google Spanner Architecture—Query Layer”
https://blog.yugabyte.com/distributed-postgresql-on-a-google-spanner-architecture-query-layer/
YugabyteDB uses the PostgreSQL source code for its SQL upper half.
Regards, Bryn Llewellyn, Yugabyte
From | Date | Subject | |
---|---|---|---|
Next Message | Vik Fearing | 2020-02-15 02:28:07 | Re: jsonb_object() seems to be buggy. jsonb_build_object() is good. |
Previous Message | Tom Lane | 2020-02-15 01:46:07 | Re: Use LN_S instead of "ln -s" in Makefile |