postgrespro/jsquery

Contained in operator (<@) does not work

alekbarszczewski opened this issue · 4 comments

create extension if not exists jsquery;
drop table if exists contained_test;
create table contained_test (data jsonb);
insert into contained_test values ('{"id": 1}'), ('{"id": 2}');
select * from contained_test where data @@ 'id IN (1, 2)'::jsquery; -- works, returning both records
select * from contained_test where data @@ 'id <@ [1, 2]'::jsquery; -- does not work, returning 0 rows

Using Jsquery 1.0 (compiled few days ago from master).

In readme it states that Jsquery supports "contained in" (<@) operator. Am I doing something wrong?

<@, @> and && operators should be used when both operands are arrays. In your example left operand is scalar, this is why operators return false.
For instance, in the following example both records will be returned.

drop table if exists contained_test;
create table contained_test (data jsonb);
insert into contained_test values ('{"id": [1]}'), ('{"id": [2]}');
select * from contained_test where data @@ 'id <@ [1, 2]'::jsquery;

@akorotkov Thanks! Shouldn't <non_array> <@ [...] throw error then?

Json could be very variadic and we think that jsquery should not emit any error
if struct of jsonb is differ that jsquery thinks.

Aleksander Barszczewski wrote:

@akorotkov https://github.com/akorotkov Thanks! Shouldn't |<non_array> <@
[...]| throw error then?


Reply to this email directly or view it on GitHub
#19 (comment).

Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

Ok thanks.