On Thu, Jun 20, 2024 at 7:30 PM jian he <jian.universal...@gmail.com> wrote:

> "predicate check expressions return the single three-valued result of
>
the predicate: true, false, or unknown."
> "unknown" is wrong, because `select 'unknown'::jsonb;` will fail.
> here "unknown" should be "null"? see jsonb_path_query doc entry also.
>
>
The syntax for json_exists belies this claim (assuming our docs are
accurate there).  Its "on error" options are true/false/unknown.
Additionally, the predicate test operator is named "is unknown" not "is
null".

The result of the predicate test, which is never produced as a value, only
a concept, is indeed "unknown" - which then devolves to false when it is
practically applied to determining whether to output the path item being
tested.  As it does also when used in a parth expression.

postgres=# select json_value('[null]','$[0] < 1');
 json_value
------------
 f

postgres=# select json_value('[null]','$[0] == null');
 json_value
------------
 t

Not sure how to peek inside the jsonpath system here though...

postgres=# select json_value('[null]','($[0] < 1) == null');
ERROR:  syntax error at or near "==" of jsonpath input
LINE 1: select json_value('[null]','($[0] < 1) == null');

I am curious if that produces true (the unknown is left as null) or false
(the unknown becomes false immediately).

David J.

Reply via email to