Re: jsonb_object() seems to be buggy. jsonb_build_object() is good. - Mailing list pgsql-hackers

From Bryn Llewellyn
Subject Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.
Date
Msg-id 7466A4F3-EBA2-4819-ABFE-A5FD0E974D63@yugabyte.com
Whole thread Raw
In response to Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.  (Vik Fearing <vik@postgresfriends.org>)
Responses Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.
Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.
Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.
List pgsql-hackers
This:

select jsonb_pretty(jsonb_build_object(
 'a'::varchar, 1.7::numeric,
 'b'::varchar, 'dog'::varchar,
 'c'::varchar, true::boolean
 ))

allows me to express what I want. That’s a good thing. Are you saying that this:

select jsonb_pretty(jsonb_object(
 '{a, 17, b, "dog", c, true}'::varchar[]
 ))

simply lacks that power of expression and that every item in the array is assumed to be intended to end up as a JSON
textprimitive value? In other words, do the double quotes around "dog" have no effect? That would be a bad thing—and it
wouldlimit the usefulness of the jsonb_object() function. 

The doc (“Builds a JSON object out of a text array.”) is simply too terse to inform an answer to this question.

On 14-Feb-2020, at 18:28, Vik Fearing <vik@postgresfriends.org> wrote:

On 15/02/2020 03:21, Bryn Llewellyn wrote:
> 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
lessverbose. 
>
> 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. 

They haven't been implicitly converted, you gave an array of varchars.
How should it know that you don't want texts?

> Do you agree that this is a bug?
No.
--
Vik Fearing




pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [HACKERS] Moving relation extension locks out of heavyweight lock manager
Next
From: Amit Kapila
Date:
Subject: Re: [HACKERS] Moving relation extension locks out of heavyweight lock manager