jsonb_object() seems to be buggy. jsonb_build_object() is good.

Поиск
Список
Период
Сортировка
От Bryn Llewellyn
Тема jsonb_object() seems to be buggy. jsonb_build_object() is good.
Дата
Msg-id E1529841-8E71-4CA1-8B75-95527086D820@yugabyte.com
обсуждение исходный текст
Ответы Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.  (Vik Fearing <vik@postgresfriends.org>)
Список 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
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




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Use LN_S instead of "ln -s" in Makefile
Следующее
От: Vik Fearing
Дата:
Сообщение: Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.