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

2020-02-16 Thread Bryn Llewellyn
On 16-Feb-2020, at 16:40, Andrew Dunstan wrote: On 2/16/20 7:25 PM, Bryn Llewellyn wrote: > > B.t.w., you earlier said “The double quotes [around “dog”] serve a specific > purpose, to allow values containing commas to be treated as a single value > (see syntax details for the exact rules) in

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

2020-02-16 Thread Andrew Dunstan
On 2/16/20 7:25 PM, Bryn Llewellyn wrote: > > B.t.w., you earlier said “The double quotes [around “dog”] serve a specific > purpose, to allow values containing commas to be treated as a single value > (see syntax details for the exact rules) in the resulting array of text > values.” But this

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

2020-02-16 Thread Bryn Llewellyn
Andrew Dunstan wrote: Bryn Llewellyn wrote: > > Andrew replied > > The function above has many deficiencies, including lack of error > checking and use of 'execute' which will significantly affect > performance. Still, if it works for you, that's your affair. > > These functions were written

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

2020-02-16 Thread Andrew Dunstan
On 2/16/20 1:40 PM, Bryn Llewellyn wrote: > > Andrew replied > > The function above has many deficiencies, including lack of error > checking and use of 'execute' which will significantly affect > performance. Still, if it works for you, that's your affair. > > These functions were written to

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

2020-02-16 Thread Bryn Llewellyn
Bryn Llewellyn wrote: > ...I wrote my own wrapper for jsonb_build_array() > and jsonb_build_object(): > > create function my_jsonb_build( > kind in varchar, > variadic_elements in varchar) > returns jsonb > immutable > language plpgsql > as $body$ > declare > stmt varchar := >

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

2020-02-15 Thread Andrew Dunstan
On 2/15/20 12:06 AM, Bryn Llewellyn wrote: > Thank you both, Vik, and David, for bing so quick to respond. All is > clear now. It seems to me that the price (giving up the ability to say > explicitly what primitive JSON values you want) is too great to pay > for the benefit (being able to build

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

2020-02-14 Thread Bryn Llewellyn
Thank you both, Vik, and David, for bing so quick to respond. All is clear now. It seems to me that the price (giving up the ability to say explicitly what primitive JSON values you want) is too great to pay for the benefit (being able to build the semantic equivalent of a variadic list of

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

2020-02-14 Thread David G. Johnston
On Friday, February 14, 2020, Bryn Llewellyn wrote: > > > select jsonb_pretty(jsonb_object( > '{a, 17, b, "dog", c, true}'::varchar[] > )) > > In other words, do the double quotes around "dog" have no effect? That > would be a bad thing—and it would limit the usefulness of the > jsonb_object()

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

2020-02-14 Thread David G. Johnston
On Friday, February 14, 2020, Bryn Llewellyn wrote: > > The doc (“Builds a JSON object out of a text array.”) is simply too terse > to inform an answer to this question. > It does presume knowledge but it precisely defines the outcome: PostgreSQL arrays are typed and all members are of the same

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

2020-02-14 Thread Vik Fearing
On 15/02/2020 04:07, Bryn Llewellyn wrote: > 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

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

2020-02-14 Thread Bryn Llewellyn
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[]

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

2020-02-14 Thread Vik Fearing
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

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

2020-02-14 Thread Bryn Llewellyn
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,