Re: SQL/JSON path issues/questions

From: Steven Pousty <steve(dot)pousty(at)gmail(dot)com>
To: Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
Cc: Thom Brown <thom(at)linux(dot)com>, Liudmila Mantrova <l(dot)mantrova(at)postgrespro(dot)ru>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SQL/JSON path issues/questions
Date: 2019-07-19 18:53:00
Message-ID: CAKmB1PGMvPYFrcv+Fd=Dih3yqUhdBewNexukOUCmphSbmAE2jg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I would like to help review this documentation. Can you please point me in
the right direction?
Thanks
Steve

On Fri, Jul 19, 2019 at 2:02 AM Alexander Korotkov <
a(dot)korotkov(at)postgrespro(dot)ru> wrote:

> On Thu, Jul 18, 2019 at 5:08 PM Thom Brown <thom(at)linux(dot)com> wrote:
> > On Tue, 16 Jul 2019 at 19:44, Alexander Korotkov
> > <a(dot)korotkov(at)postgrespro(dot)ru> wrote:
> > >
> > > On Tue, Jul 16, 2019 at 9:22 PM Thom Brown <thom(at)linux(dot)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?
>
> The point of existing operator analogues is index support. We
> introduced operators for searches we can accelerate using GIN indexes.
>
> jsonb_path_query() doesn't return bool. So, even if we have an
> operator for that, it wouldn't get index support.
>
> However, we can discuss introduction of operator analogues for other
> functions as syntax sugar.
>
> ------
> Alexander Korotkov
> Postgres Professional: http://www.postgrespro.com
> The Russian Postgres Company
>
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-07-19 18:56:34 Re: pgsql: Sync our copy of the timezone library with IANA release tzcode20
Previous Message Robert Haas 2019-07-19 18:50:22 Re: should there be a hard-limit on the number of transactions pending undo?