Re: Patch: Improve Boolean Predicate JSON Path Docs
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "David E. Wheeler" <david@justatheory.com>
Cc: Alexander Korotkov <aekorotkov@gmail.com>, Erik Wienhold <ewie@ewie.name>,
pgsql-hackers@lists.postgresql.org
Date: 2024-01-21T19:34:19Z
Lists: pgsql-hackers
Attachments
- jsonpath-exists-semantics-fix-wip.patch (text/x-diff) patch
"David E. Wheeler" <david@justatheory.com> writes: > On Jan 20, 2024, at 12:34, Tom Lane <tgl@sss.pgh.pa.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
Commits
-
Doc: improve documentation for jsonpath behavior.
- 7014c9a4bba2 17.0 landed
-
Ensure we have a snapshot while dropping ON COMMIT DROP temp tables.
- 54b208f90963 17.0 cited