From: | Amit Langote <amitlangote09(at)gmail(dot)com> |
---|---|
To: | Himanshu Upadhyaya <upadhyaya(dot)himanshu(at)gmail(dot)com> |
Cc: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, jian he <jian(dot)universality(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Erik Rijkers <er(at)xs4all(dot)nl>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com> |
Subject: | Re: remaining sql/json patches |
Date: | 2024-03-12 12:07:01 |
Message-ID: | CA+HiwqE6kVsjDXg95+cEaErbUjecgrS_qTgcfV7MNT3k+58swA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi Himanshu,
On Tue, Mar 12, 2024 at 6:42 PM Himanshu Upadhyaya
<upadhyaya(dot)himanshu(at)gmail(dot)com> wrote:
>
> Hi,
>
> wanted to share the below case:
>
> ‘postgres[146443]=#’SELECT JSON_EXISTS(jsonb '{"customer_name": "test", "salary":1000, "department_id":1}', '$.* ? (@== $dept_id && @ == $sal)' PASSING 1000 AS sal, 1 as dept_id);
> json_exists
> -------------
> f
> (1 row)
>
> isn't it supposed to return "true" as json in input is matching with both the condition dept_id and salary?
I think you meant to use || in your condition, not &&, because 1000 != 1.
See:
SELECT JSON_EXISTS(jsonb '{"customer_name": "test", "salary":1000,
"department_id":1}', '$.* ? (@ == $dept_id || @ == $sal)' PASSING 1000
AS sal, 1 as dept_id);
json_exists
-------------
t
(1 row)
Or you could've written the query as:
SELECT JSON_EXISTS(jsonb '{"customer_name": "test", "salary":1000,
"department_id":1}', '$ ? (@.department_id == $dept_id && @.salary ==
$sal)' PASSING 1000 AS sal, 1 as dept_id);
json_exists
-------------
t
(1 row)
Does that make sense?
In any case, JSON_EXISTS() added by the patch here returns whatever
the jsonpath executor returns. The latter is not touched by this
patch. PASSING args, which this patch adds, seem to be working
correctly too.
--
Thanks, Amit Langote
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Korotkov | 2024-03-12 12:10:59 | Re: collect_corrupt_items_vacuum.patch |
Previous Message | Matthias van de Meent | 2024-03-12 11:50:24 | Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements |