Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XzZcg-0003Uh-5b for pgsql-performance@arkaria.postgresql.org; Fri, 12 Dec 2014 23:27:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XzZcf-0005ud-Bf for pgsql-performance@arkaria.postgresql.org; Fri, 12 Dec 2014 23:27:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XzZcd-0005uQ-4U; Fri, 12 Dec 2014 23:27:43 +0000 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XzZcZ-0006No-5i; Fri, 12 Dec 2014 23:27:41 +0000 Received: from mfilter32-d.gandi.net (mfilter32-d.gandi.net [217.70.178.163]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 96235A80AD; Sat, 13 Dec 2014 00:27:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter32-d.gandi.net Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by mfilter32-d.gandi.net (mfilter32-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id A6s4RBYgjUpy; Sat, 13 Dec 2014 00:27:34 +0100 (CET) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 169BCA80B0; Sat, 13 Dec 2014 00:27:32 +0100 (CET) Message-ID: <548B79E3.5070301@dunslane.net> Date: Fri, 12 Dec 2014 18:27:31 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Tom Lane , Josh Berkus CC: Tim Dudgeon , pgsql-sql@postgresql.org, pgsql-performance@postgresql.org Subject: Re: Re: [SQL] querying with index on jsonb slower than standard column. Why? References: <5484DBDA.6090405@gmail.com> <5484EEA7.1030403@aklaver.com> <5484F437.2080402@gmail.com> <16147.1418002090@sss.pgh.pa.us> <5485C449.4020204@aklaver.com> <26002.1418053572@sss.pgh.pa.us> <5485C8BA.7040704@aklaver.com> <5485D584.8080105@aklaver.com> <27877.1418057764@sss.pgh.pa.us> <3936.1418071989@sss.pgh.pa.us> <548614C8.90203@aklaver.com> <54861A81.8030509@gmail.com> <548B5CF4.4030009@agliodbs.com> <8867.1418420650@sss.pgh.pa.us> In-Reply-To: <8867.1418420650@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 12/12/2014 04:44 PM, Tom Lane wrote: > Josh Berkus writes: >> Yeah, I believe the core problem is that Postgres currently doesn't have >> any way to have variadic return times from a function which don't match >> variadic input types. Returning a value as an actual numeric from JSONB >> would require returning a numeric from a function whose input type is >> text or json. So a known issue but one which would require a lot of >> replumbing to fix. > Well, it'd be easy to fix if we were willing to invent distinct operators > depending on which type you wanted out (perhaps ->> for text output as > today, add ->># for numeric output, etc). That was my immediate reaction. Not sure about the operator name. I'd tentatively suggest -># (taking an int or text argument) and #># taking a text[] argument, both returning numeric, and erroring out if the value is a string, boolean, object or array. > Doesn't seem terribly nice > from a usability standpoint though. > > The usability issue could be fixed by teaching the planner to fold a > construct like (jsonb ->> 'foo')::numeric into (jsonb ->># 'foo'). > But I'm not sure how we do that except in a really ugly and ad-hoc > fashion. > > I would be inclined to add the operator and see how cumbersome people find it. I suspect in many cases it might be sufficient. cheers andrew -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance