pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #11768: "jsonb ?" - not support int type operator
2+ messages / 2 participants
[nested] [flat]
* BUG #11768: "jsonb ?" - not support int type operator
@ 2014-10-22 23:57 ua.san.alex@gmail.com
2014-12-17 14:18 ` Re: BUG #11768: "jsonb ?" - not support int type operator Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 2+ messages in thread
From: ua.san.alex@gmail.com @ 2014-10-22 23:57 UTC (permalink / raw)
To: pgsql-bugs
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.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #11768: "jsonb ?" - not support int type operator
2014-10-22 23:57 BUG #11768: "jsonb ?" - not support int type operator ua.san.alex@gmail.com
@ 2014-12-17 14:18 ` Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 0 replies; 2+ messages in thread
From: Alvaro Herrera @ 2014-12-17 14:18 UTC (permalink / raw)
To: ua.san.alex@gmail.com; +Cc: pgsql-bugs
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2014-12-17 14:18 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-10-22 23:57 BUG #11768: "jsonb ?" - not support int type operator ua.san.alex@gmail.com
2014-12-17 14:18 ` Alvaro Herrera <alvherre@2ndquadrant.com>
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