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

From: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
To: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, pgsql-hackers list <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.
Date: 2020-02-17 00:40:12
Message-ID: e9d17417-0e10-5b17-d396-1b2214ca90b6@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


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 test shows that they are not needed for that purpose:

I didn't say that. Someone else did.

>
> select jsonb_pretty(jsonb_object(
> '{a, 17, b, dog house, c, true}'::varchar[]
> ))
>
> This is the result:
>
> { +
> "a": "17", +
> "b": "dog house",+
> "c": "true" +
> }
>
> The commas are sufficient separators.
>
> It seems to me, therefore, that writing the double quotes gives the wrong message: they make it look like you are indeed specifying a text value rather than a numeric or integer value. But we know that the double quotes do *not* achieve this.
>

No, you haven't understood what they said. If the field value contains a
comma it needs to be quoted. But none of the fields in your example do.
If your field were "dog,house" instead of "dog house" it would need to
be quoted. This had nothing to do with json, BTW, it's simply from the
rules for array literals.

cheers

andrew

--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2020-02-17 01:40:46 Re: 1 Status of vertical clustered index - 2 Join using (fk_constraint) suggestion - 3 Status of pgsql's parser autonomization
Previous Message Bryn Llewellyn 2020-02-17 00:25:20 Re: jsonb_object() seems to be buggy. jsonb_build_object() is good.