Re: SQL/JSON path issues/questions
Thom Brown <thom@linux.com>
From: Thom Brown <thom@linux.com>
To: Alexander Korotkov <a.korotkov@postgrespro.ru>
Cc: Liudmila Mantrova <l.mantrova@postgrespro.ru>,
Kyotaro Horiguchi <horikyota.ntt@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2019-07-18T14:08:06Z
Lists: pgsql-hackers
On Tue, 16 Jul 2019 at 19:44, Alexander Korotkov
<a.korotkov@postgrespro.ru> wrote:
>
> On Tue, Jul 16, 2019 at 9:22 PM Thom Brown <thom@linux.com> wrote:
> > Now I'm looking at the @? and @@ operators, and getting a bit
> > confused. This following query returns true, but I can't determine
> > why:
> >
> > # SELECT '{"a":[1,2,3,4,5]}'::jsonb @? '$.b == "hello"'::jsonpath;
> > ?column?
> > ----------
> > t
> > (1 row)
> >
> > "b" is not a valid item, so there should be no match. Perhaps it's my
> > misunderstanding of how these operators are supposed to work, but the
> > documentation is quite terse on the behaviour.
>
> So, the result of jsonpath evaluation is single value "false".
>
> # SELECT jsonb_path_query_array('{"a":[1,2,3,4,5]}'::jsonb, '$.b == "hello"');
> jsonb_path_query_array
> ------------------------
> [false]
> (1 row)
>
> @@ operator checks that result is "true". This is why it returns "false".
>
> @? operator checks if result is not empty. So, it's single "false"
> value, not empty list. This is why it returns "true".
>
> Perhaps, we need to clarify this in docs providing more explanation.
Understood. Thanks.
Also, is there a reason why jsonb_path_query doesn't have an operator analog?
Thom
Commits
-
Fixes for jsonpath filter expression elements table in docs
- 1ed89826b82c 12.0 landed
- 0cea6eb5a5f2 13.0 landed
-
Assorted fixes for jsonpath documentation
- a5c2f3a346fc 12.0 landed
- 5a7d697a3936 13.0 landed
-
Fix description for $varname jsonpath variable
- dfd79e2d0e8f 12.0 landed
-
Improve documentation for jsonpath like_regex predicate
- 1ff8dc9f19dd 12.0 landed
-
Support 'q' flag in jsonpath 'like_regex' predicate
- 261a5c192856 12.0 landed