Re: Patch: Improve Boolean Predicate JSON Path Docs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
Cc: Alexander Korotkov <aekorotkov(at)gmail(dot)com>, Erik Wienhold <ewie(at)ewie(dot)name>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Patch: Improve Boolean Predicate JSON Path Docs
Date: 2024-01-21 19:34:19
Message-ID: 3455944.1705865659@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"David E. Wheeler" <david(at)justatheory(dot)com> writes:
> On Jan 20, 2024, at 12:34, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Surely we're not helping anybody by leaving that behavior in place.
>> Making it do something useful, throwing an error, or returning NULL
>> all seem superior to this. I observe that @@ returns NULL for the
>> path type it doesn't like, so maybe that's what to do here.

> I agree it would be far better for the behavior to be consistent, but frankly would like to see them raise an error. Ideally the hit would suggest the proper alternative operator or function to use, and maybe link to the docs that describe the difference between SQL-standard JSONPath and "predicate check expressions”, and how they have separate operators and functions.

That ship's probably sailed. However, I spent some time poking into
the odd behavior I showed for @?, and it seems to me that it's an
oversight in appendBoolResult. That just automatically returns jperOk
in the !found short-circuit path for any boolean result, which is not
the behavior you'd get if the boolean value were actually returned
(cf. jsonb_path_match_internal). I experimented with making it do
what seems like the right thing, and found that there is only one
regression test case that changes behavior:

select jsonb '2' @? '$ == "2"';
?column?
----------
- t
+ f
(1 row)

Now, JSON does not think that numeric 2 equals string "2", so
ISTM the expected output here is flat wrong. It's certainly
inconsistent with @@:

regression=# select jsonb '2' @@ '$ == "2"';
?column?
----------

(1 row)

So I think we should consider a patch like the attached
(probably with some more test cases added). I don't really
understand this code however, so maybe I missed something.

regards, tom lane

Attachment Content-Type Size
jsonpath-exists-semantics-fix-wip.patch text/x-diff 1.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-01-21 19:43:26 Re: Patch: Improve Boolean Predicate JSON Path Docs
Previous Message David E. Wheeler 2024-01-21 19:24:12 Re: Patch: Improve Boolean Predicate JSON Path Docs