Hackers, Another apparent inconsistency I’ve noticed in jsonpath queries is the treatment of the && and || operators: They can’t operate on 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