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
thenumeric 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
JSONprimitive 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