Re: SQL/JSON path issues/questions
Chapman Flack <chap@anastigmatix.net>
From: Chapman Flack <chap@anastigmatix.net>
To: Alexander Korotkov <a.korotkov@postgrespro.ru>,
Thom Brown <thom@linux.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2019-06-17T20:57:19Z
Lists: pgsql-hackers
On 6/17/19 4:13 PM, Alexander Korotkov wrote: > On Mon, Jun 17, 2019 at 8:40 PM Thom Brown <thom@linux.com> wrote: >>>> "is unknown" suggests a boolean output, but the example shows an >>>> output of "infinity". While I understand what it does, this appears >>>> inconsistent with all other "is..." functions (e.g. is_valid(lsn), >>>> pg_is_other_temp_schema(oid), pg_opclass_is_visible(opclass_oid), >>>> pg_is_in_backup() etc.). >>> >>> It's the right behavior. Among them, only "infinity" gives >>> "unknown' for the test (@ > 0). -1 gives false, 2 and 3 true. >> >> I still find it counter-intuitive. > > It might be so. But it's defined do in SQL Standard 2016. IIUC, this comes about simply because the JSON data model for numeric values does not have any infinity or NaN. So the example given in our doc is sort of a trick example that does double duty: it demonstrates that (@ > 0) is Unknown when @ is a string, because numbers and strings are incomparable, and it *also* sort of slyly reminds the reader that JSON numbers have no infinity, and therefore "infinity" is nothing but a run-of-the-mill string. But maybe it is just too brow-furrowingly clever to ask one example to make both of those points. Maybe it would be clearer to use some string other than "infinity" to make the first point: [-1, 2, 7, "some string"] | $[*] ? ((@ > 0) is unknown) | "some string" ... and then if the reminder about infinity is worth making, repeat the example: [-1, 2, 7, "infinity"] | $[*] ? ((@ > 0) is unknown) | "infinity" with a note that it's a trick example as a reminder that JSON numbers don't have infinity or NaN and so it is no different from any other string. Regards, -Chap
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