Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2cky-0001Nu-MQ for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Oct 2017 12:38:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e2cky-0005PW-6C for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Oct 2017 12:38:32 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e2ckx-0005Op-72 for pgsql-bugs@postgresql.org; Thu, 12 Oct 2017 12:38:31 +0000 Received: from mail-qt0-x22b.google.com ([2607:f8b0:400d:c0d::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e2cku-0001tq-1Z for pgsql-bugs@postgresql.org; Thu, 12 Oct 2017 12:38:29 +0000 Received: by mail-qt0-x22b.google.com with SMTP id p1so13303436qtg.2 for ; Thu, 12 Oct 2017 05:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=q/BFpKoaj6Yxe50hlLSZR0ZWbDZpaQtqZKKEs7d6U2Q=; b=K2TeasHP6P+PTlZSofdIKN+qJxpI4RmMfWWHw9BMSQC31xuWfiCwIfxVq5Ijz33Z7T dD+qmnkv9GroauWBaEh0YpCdUxjqC/qRSMHi0E9HfPPHZ7ZozafE4xLCnNMRZGy2vz0G rxbkjV5xRl2j4h5swhsOgg3CRfMPT+ckXWlloFW0kzHm5puBFQ/AhA6uz2EbLvU1xTXn 8aH8ZF03yVhNKwMDg/pnbGDRxTocmdcvqbnaTyz77H2yFsfp6WYSuj/RjR1kpawhky7O 5lrzwKmsZwgJDqLbQMJI36hCcqbzFsLZ8O+hX9wdZRrvkPW5W7NAad303XieELyGNmbf jEXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=q/BFpKoaj6Yxe50hlLSZR0ZWbDZpaQtqZKKEs7d6U2Q=; b=hGCQV2TaSVWz5ezpUOMCJzs5PtHIJzwAZ23TbZQBfTYxrb6g1j4tMMPQqiOur552+N e5CdiGmQPbOeIq9yTNfHJFqksyPJ3LfESImRDm6ntPMOXe1laI4UjgG0f470J9wIsW7T F+lIvFBhJfZ3ejsE4VYb9IDllKkJdsjE7ylNahCMtPbgANfLrscRdpVKRySl3dP3SbXI d6zaTfp/axJxV2L1pdVvPEEhyWi0aU98tZPOVXZC0hHHM5/XvX/CiVGzJ3WcqwhJIgly PMeRb27XwBU3WNA4QC04GLevXGrrj+dJFyEXFmexYMNCXSmp3dwIKIAYoES0Y3dCmW7L nxCw== X-Gm-Message-State: AMCzsaWevIf+2Jv5SH0cWfHCj9BluoAfw9QTPoUnGY9QxdlC0sxz03aR lomdg/KKakmAiZ9eP04hAjkM9FgmKwoMCmsVRZ8IOc8C6ZovkvL3on/DyyXbOyrhxTMhuZ3gEhB tIgBhPhLJGQwNqnTkeH3ItfnW5I9WZfTXjFZLb49QeMQO3PYeDLC6y/CbQvhytEPG1JyeQLf0eU cO4RsZqFeH X-Google-Smtp-Source: AOwi7QASTzjiGBeDIVVQ+XLROxhryNlBYuWaXGZPQXSRjb2J8biHjWXlqolhKSdxqp1USYfFlfmEkw== X-Received: by 10.129.14.130 with SMTP id 124mr1635533ywo.133.1507811906868; Thu, 12 Oct 2017 05:38:26 -0700 (PDT) Received: from [192.168.10.146] ([98.122.175.38]) by smtp.gmail.com with ESMTPSA id j196sm2245958ywg.79.2017.10.12.05.38.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Oct 2017 05:38:26 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much To: Michael Paquier , Marko Tiikkaja Cc: PostgreSQL mailing lists References: <20171011020058.27986.42308@wrigleys.postgresql.org> Message-ID: <76ff5ede-99a7-536b-4c26-0db0748ea6e1@2ndQuadrant.com> Date: Thu, 12 Oct 2017 08:38:25 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-MW List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 10/12/2017 12:42 AM, Michael Paquier wrote: > On Wed, Oct 11, 2017 at 11:00 AM, 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