Re: minor doc issue in 9.16.2.1.1. Boolean Predicate Check Expressions

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: minor doc issue in 9.16.2.1.1. Boolean Predicate Check Expressions
Date: 2024-10-17 13:59:19
Message-ID: ZxEYNzZEOpzod3_B@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 17, 2024 at 02:07:00PM +0800, jian he wrote:
> On Thu, Oct 17, 2024 at 7:59 AM Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >
> >
> > Where are we on this? I still see this behavior.
> >
> > ---------------------------------------------------------------------------
>
> > > but I found following two examples returning different results,
> > > i think they should return the same value.
> > > select json_value('1', '$ == "1"' returning jsonb error on error);
> > > select json_query('1', '$ == "1"' returning jsonb error on error);
>
> This part has been resolved.
> see section Note section in
> https://www.postgresql.org/docs/current/functions-json.html#SQLJSON-QUERY-FUNCTIONS

Okay, good.

> > > >> 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.
> > > >>
>
> doc (https://www.postgresql.org/docs/devel/functions-json.html#FUNCTIONS-SQLJSON-CHECK-EXPRESSIONS)
> <<QUOTE>>
> While SQL-standard path expressions return the relevant element(s) of
> the queried JSON value, predicate check expressions return the single
> three-valued result of the predicate: true, false, or unknown.
> <<END OF QUOTE>>
>
> https://www.postgresql.org/docs/current/datatype-boolean.html
> says
> "The boolean type can have several states: “true”, “false”, and a
> third state, “unknown”, which is represented by the SQL null value."
>
> but here
> select jsonb_path_query('1', '$ == "a"');
> return JSON null value, not SQL null value.
>
> however.
> select jsonb_path_match('1', '$ == "a"');
> return SQL null value.
>
>
> maybe we can change to
> "predicate check expressions return the single three-valued result of
> the predicate: true, false, or null"

Yes, done in the attached patch.

> Then in the <note> section mention that
> when Predicate check expressions cannot be applied, it returns JSON
> null for function jsonb_path_query,
> return SQL NULL for function jsonb_path_match or @@ operator.

The section is titled, "9.16.2.1. Deviations from the SQL Standard". Is
this a deviation from the standard? If not, I think we have to
distinguish SQL null and JSON null somewhere else. Is the "Note" text
also a deviation?

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

When a patient asks the doctor, "Am I going to die?", he means
"Am I going to die soon?"

Attachment Content-Type Size
json.diff text/x-diff 681 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Shayon Mukherjee 2024-10-17 13:59:34 Re: Proposal to Enable/Disable Index using ALTER INDEX (with patch)
Previous Message Tom Lane 2024-10-17 13:56:30 Re: doc: virtual envs with Pl/Python