From: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
To: Michael Paquier <michael.paquier@gmail.com>
To: Marko Tiikkaja <marko@joh.to>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much
Date: Thu, 12 Oct 2017 08:38:25 -0400
Message-ID: <76ff5ede-99a7-536b-4c26-0db0748ea6e1@2ndQuadrant.com> (raw)
In-Reply-To: <CAB7nPqSDHmjE-6HS-RUufZMEc6qipBDNjL1HktcMagVn7pGOcw@mail.gmail.com>
References: <20171011020058.27986.42308@wrigleys.postgresql.org>
<CAB7nPqSDHmjE-6HS-RUufZMEc6qipBDNjL1HktcMagVn7pGOcw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 10/12/2017 12:42 AM, Michael Paquier wrote:
> On Wed, Oct 11, 2017 at 11:00 AM, <marko@joh.to> wrote:
>> This query fails with an unreasonable error message:
>>
>> =# SELECT jsonb_build_object(VARIADIC '{a,b}'::text[]);
>> ERROR: invalid number of arguments: object must be matched key value
>> pairs
>>
>> jsonb_object(text[]) can be used instead in this case, so perhaps
>> jsonb_build_object() could simply point to that one if a variadic call like
>> this is made?
> It looks like a good idea to do so for this code. It seems that nobody
> has actually bothered testing those functions in more fancy ways than
> the documentation shows... And I think that this is not the only
> problem.
>
> I looked as well at jsonb_build_array(), which also uses VARIADIC ANY,
> being surprised by that:
> =# SELECT jsonb_build_array(variadic '{a,b}'::text[]);
> jsonb_build_array
> -------------------
> [["a", "b"]]
> (1 row)
> But it seems to me that when a variadic call is used, then ["a", "b"]
> is the correct result, no?
>
> The json_* equivalent functions are reacting similarly than the jsonb_* ones.
>
> It is actually possible to make the difference between a variadic and
> a non-variadic call by looking at funcvariadic in
> fcinfo->flinfo->fn_expr. So my suggestion of a fix would be the
> following:
> - refactor jsonb_object with an _internal routine that gets called as
> well for variadic calls of jsonb_build_object. Something equivalent
> needs to be done for the json functions.
> - for json[b]_build_array, let's check if the input is a variadic
> call, then fill in an intermediate structure with all the array
> values, which is used with the existing processing.
>
> More regression tests are needed as well. Andrew, you worked on most
> of those items, including 7e354ab9, what is your opinion on the
> matter?
If the case of an explicit VARIADIC parameter doesn't work the same way
then certainly it's a bug which needs to be fixed, and for which I
apologise. If you have time to produce a patch I will review it. Your
plan sounds good.
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: andrew.dunstan@2ndquadrant.com, michael.paquier@gmail.com, marko@joh.to
Subject: Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much
In-Reply-To: <76ff5ede-99a7-536b-4c26-0db0748ea6e1@2ndQuadrant.com>
References: <20171011020058.27986.42308@wrigleys.postgresql.org> <CAB7nPqSDHmjE-6HS-RUufZMEc6qipBDNjL1HktcMagVn7pGOcw@mail.gmail.com> <76ff5ede-99a7-536b-4c26-0db0748ea6e1@2ndQuadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox