jsonpath: Missing Binary Execution Path?

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: jsonpath: Missing Binary Execution Path?
Date: 2024-06-13 15:32:38
Message-ID: 551C85FD-C79C-4FCF-9563-014E74B41F70@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dmitry Dolgov 2024-06-13 15:33:57 Re: libpq contention due to gss even when not using gss
Previous Message Tom Lane 2024-06-13 15:25:37 Re: Improve the granularity of PQsocketPoll's timeout parameter?