Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1FR2-0003OD-JL for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Dec 2014 14:18:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y1FR1-0004W6-Mr for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Dec 2014 14:18:39 +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 1Y1FR1-0004W0-2Y for pgsql-bugs@postgresql.org; Wed, 17 Dec 2014 14:18:39 +0000 Received: from outmail148110.authsmtp.com ([62.13.148.110]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1FQs-0001Ux-I3 for pgsql-bugs@postgresql.org; Wed, 17 Dec 2014 14:18:38 +0000 Received: from mail-c235.authsmtp.com (mail-c235.authsmtp.com [62.13.128.235]) by punt14.authsmtp.com (8.14.2/8.14.2) with ESMTP id sBHEISD6018859; Wed, 17 Dec 2014 14:18:28 GMT Received: from alvin.alvh.no-ip.org (pc-144-132-215-201.cm.vtr.net [201.215.132.144]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id sBHEIOLM090606; Wed, 17 Dec 2014 14:18:26 GMT Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 3C5B4601; Wed, 17 Dec 2014 11:18:36 -0300 (CLST) Date: Wed, 17 Dec 2014 11:18:36 -0300 From: Alvaro Herrera To: ua.san.alex@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #11768: "jsonb ?" - not support int type operator Message-ID: <20141217141836.GC1768@alvh.no-ip.org> References: <20141022235702.2662.82328@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20141022235702.2662.82328@wrigleys.postgresql.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Server-Quench: 910da304-85f7-11e4-b396-002590a15da7 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZcSBoa BzkeAQdJTRslYBtL RB4bawxAL0wMSABN M15eIxoJcUtFGhZ1 VjUUWVRVVE1wXWl0 YwBTa0tfYktQXQRv TklKQExTEAF3BBQG GR5QEWsKAnw5BANw bEZkXnYVWUZ5cwh0 Q04ARG4GYXpobTYY TUFZIgdJIgBDeAJF alJ6XXNcYGBTN30u JQJhdwMbABpkHWx/ fy5FZgtLHhhbTHZ2 RQsFGz9nSgdNAm17 KRs6YkUBBF4WKFl6 MF09EU4JKxJaDRVT BUhRBzUx X-Authentic-SMTP: 61633235383639.1023:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 201.215.132.144/587 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Pg-Spam-Score: -2.6 (--) 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 ua.san.alex@gmail.com wrote: > The following bug has been logged on the website: > > Bug reference: 11768 > Logged by: Alex > Email address: ua.san.alex@gmail.com > PostgreSQL version: 9.4beta2 > Operating system: CentOS 7 > Description: > > Error - SELECT '[2, 5, 9]'::jsonb ? 5 > > Support for numeric types is very important, without it, it is not > convenient. Not sure that would do what you want anyway: alvherre=# select '[2,5,9]'::jsonb ? '5'; ?column? ---------- f (1 fila) It only matches an element if it's of type string, as can be seen here: alvherre=# select '[2,"5",9]'::jsonb ? '5'; ?column? ---------- t (1 fila) I think primarily this operator was intended to look for keys in an object (which is why it's called "exists"), which cannot be strings; extending it to arrays might have been an afterthought. Example: alvherre=# select '{"5":"cinco"}'::jsonb ? '5'; ?column? ---------- t (1 fila) For definitional reasons, JSON keys cannot be numbers: alvherre=# select '{5:"cinco"}'::jsonb ; ERROR: invalid input syntax for type json LÍNEA 1: select '{5:"cinco"}'::jsonb ; ^ DETALLE: Expected string or "}", but found "5". CONTEXTO: JSON data, line 1: {5... I think you might be looking for the "contains" operator: alvherre=# select '[2,5,9]'::jsonb @> '5'; ?column? ---------- t (1 fila) This one only accepts a jsonb as right argument, so it won't work with a bare integer either: alvherre=# \do @> Listado de operadores Esquema | Nombre | Tipo arg izq | Tipo arg der | Tipo resultado | Descripción ------------+--------+--------------+--------------+----------------+------------- ... pg_catalog | @> | jsonb | jsonb | boolean | contains ... (13 filas) -- Álvaro Herrera http://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