Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much
Date: 2017-10-14 10:46:12
Message-ID: CAB7nPqTsuq=rnM8PQGxNS3Gh=JQQp4RmdPxGLGXSV648X4yfhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Fri, Oct 13, 2017 at 10:56 PM, Dmitry Dolgov <9erthalion6(at)gmail(dot)com> wrote:
>> On 13 October 2017 at 15:48, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
>> wrote:
>>
>> it is perfectly valid to have something like json_build_array('2', NULL)
>> or
>> json_build_object('1', NULL), because there can be NULL values in JSON
>> strings. What we just need to be careful here is to check if the array
>> is NULL or not in a variadic call, and just return NULL in this case.
>
> Oh, indeed, I agree.

Okay. Attached is an updated patch fixing what you have reported. Now
things behave as I would expect the way they should:
=# select json_build_array(variadic NULL::text[]);
json_build_array
------------------
null
(1 row)
=# select json_build_array(variadic '{}'::text[]);
json_build_array
------------------
[]
(1 row)
=# select json_build_object(variadic '{}'::text[]);
json_build_object
-------------------
{}
(1 row)
=# select json_build_object(variadic NULL::text[]);
json_build_object
-------------------
null
(1 row)

Thanks Dmitry for the review.
--
Michael

Attachment Content-Type Size
json_variadic_v2.patch text/x-patch 26.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-10-14 20:51:32 Re: Combination of ordered-set aggregate function terminates JDBC connection on PostgreSQL 9.6.5
Previous Message GDR! 2017-10-14 04:56:36 Re: BUG #14851: Systemd kills long-running recovery

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-10-14 12:33:19 Re: pg_control_recovery() return value when not in recovery
Previous Message legrand legrand 2017-10-14 07:09:39 Re: Continuous integration on Windows?