Re: ​jsonb @@ jsonpath operator doc: ​Only the first item of the result is taken into account

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Erik Wienhold <ewie(at)ewie(dot)name>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: ​jsonb @@ jsonpath operator doc: ​Only the first item of the result is taken into account
Date: 2023-04-04 01:50:42
Message-ID: CACJufxEvB3zAKcKkNLVLWfFdRHg+StY+jrFjFvwdRZduji-www@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Apr 4, 2023 at 12:22 AM Erik Wienhold <ewie(at)ewie(dot)name> wrote:

> > On 03/04/2023 17:36 CEST Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
> wrote:
> >
> > On 4/3/23 08:11, Erik Wienhold wrote:
> > >> On 02/04/2023 17:40 CEST Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
> wrote:
> > >>
> > >> That is a long way from:
> > >>
> > >> jsonb @@ jsonpath → boolean
> > >>
> > >> Returns the result of a JSON path predicate check for the specified
> JSON
> > >> value. Only the first item of the result is taken into account. If the
> > >> result is not Boolean, then NULL is returned.
> > >
> > > What do you mean? I responded to the OP's question. It's not a
> suggestion
> > > to update the docs. Obviously it's quite a mouthful and needs to be
> boiled
> > > down for the docs. Any suggestions?
> >
> > For me I don't see how:
> >
> > Predicates have existence semantics, because their operands are item
> > sequences. Pairs of items from the left and right operand's sequences
> > are checked. TRUE returned only if any pair satisfying the condition is
> > found. In strict mode, even if the desired pair has already been found,
> > all pairs still need to be examined to check the absence of errors. If
> > any error occurs, UNKNOWN (analogous to SQL NULL) is returned.
> >
> > resolves to :
> >
> > Only the first item of the result is taken into account.
> >
> > In other words reconciling "TRUE returned only if any pair satisfying
> > the condition is found." and "...first item of the result..."
>
> I see.
>
> Thinking about it now, I believe that "first item of the result" is
> redundant
> (and causing the OP's confusion) because the path predicate produces only a
> single item: true, false, or null. That's what I wanted to show with the
> first
> two jsonb_path_query examples in my initial response, where the second
> example
> returns multiple items.
>
> I think the gist of @@ and json_path_match is:
>
> "Returns true if any JSON value at the given path matches the predicate.
> Returns NULL when not a path predicate or comparing different types."
>
> --
> Erik
>
>
>
"Returns true if any JSON value at the given path matches the predicate.
> Returns NULL when not a path predicate or comparing different types."
>
in first sentence, should we add something "otherwise return false." ?
also, should it be "Return true"? (since only one value returned)?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message houzj.fnst@fujitsu.com 2023-04-04 03:13:09 RE: Support logical replication of DDLs
Previous Message Daniel Gustafsson 2023-04-03 21:52:31 Re: [PATCH] Introduce array_shuffle() and array_sample()