jsonpath: Missing Binary Execution Path? - Mailing list pgsql-hackers

From David E. Wheeler
Subject jsonpath: Missing Binary Execution Path?
Date
Msg-id 551C85FD-C79C-4FCF-9563-014E74B41F70@justatheory.com
Whole thread Raw
Responses Re: jsonpath: Missing Binary Execution Path?
Re: jsonpath: Missing Binary Execution Path?
List pgsql-hackers
Hackers,

Another apparent inconsistency I’ve noticed in jsonpath queries is the treatment of the && and || operators: They can’t
operateon scalar functions, only on other expressions. Some examples: 

david=# select jsonb_path_query('true', '$ && $');
ERROR:  syntax error at or near "&&" of jsonpath input
LINE 1: select jsonb_path_query('true', '$ && $');
                                        ^
david=# select jsonb_path_query('true', '$.boolean() && $.boolean()');
ERROR:  syntax error at or near "&&" of jsonpath input
LINE 1: select jsonb_path_query('true', '$.boolean() && $.boolean()'...
                                        ^
The only place I’ve seen them work is inside filters with binary or unary operands:

jsonb_path_query('[1, 3, 7]', '$[*] ? (@ > 1 && @ < 5)');
 jsonb_path_query
------------------
 3

It doesn’t even work with boolean methods!

david=# select jsonb_path_query('[1, 3, 7]', '$[*] ? (@.boolean() && @.boolean())');
ERROR:  syntax error at or near "&&" of jsonpath input
LINE 1: select jsonb_path_query('[1, 3, 7]', '$[*] ? (@.boolean() &&...
                                             ^
Other binary operators work just fine in these sorts of contexts:

david=# select jsonb_path_query('1', '$ >= 1');
 jsonb_path_query
------------------
 true
(1 row)

david=# select jsonb_path_query('[1, 3, 7]', '$[*] ? (@ > 1)');
 jsonb_path_query
------------------
 3
 7
(2 rows)

Should && and || not also work on scalar operands?

Best,

David





pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Improve the granularity of PQsocketPoll's timeout parameter?
Next
From: Dmitry Dolgov
Date:
Subject: Re: libpq contention due to gss even when not using gss