Re: Wrong result for comparing ROW(...) with IS NOT NULL

From: Wolfgang Walther <walther(at)technowledgy(dot)de>
To: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Wrong result for comparing ROW(...) with IS NOT NULL
Date: 2020-11-05 14:09:32
Message-ID: 4a853592-a43b-b677-5026-212196b6e9c2@technowledgy.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Pavel Borisov:
> Sure, it is described here:
> https://www.postgresql.org/docs/13/functions-comparison.html
>
> "If the /|expression|/ is row-valued, then |IS NULL| is true when the
> row expression itself is null or when all the row's fields are null,
> while |IS NOT NULL| is true when the row expression itself is non-null
> and all the row's fields are non-null. Because of this behavior, |IS
> NULL| and |IS NOT NULL| do not always return inverse results for
> row-valued expressions; in particular, a row-valued expression that
> contains both null and non-null fields will return false for both tests.
> In some cases, it may be preferable to write /|row|/|IS DISTINCT FROM
> NULL| or /|row|/|IS NOT DISTINCT FROM NULL|, which will simply check
> whether the overall row value is null without any additional tests on
> the row fields."

Thank you, that explains it very well.

When I realized there was something unexpected going on, I was looking
at all the ROW() syntax in the docs and I found this (as mentioned
upthread):

https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS

It might be worth it to either add another example for IS NOT NULL, like

SELECT ROW(table.*) IS NOT NULL FROM table; -- detect all-non-null rows

or add a link to section 9.2, that you mentioned. Or do both.

Another thing that could be improved:

Below that example there is a link to section 9.24. The link is:

https://www.postgresql.org/docs/current/functions-comparisons.html

The link you gave me to section 9.2 is (replaced 13 with current):

https://www.postgresql.org/docs/current/functions-comparison.html

Like really? The only difference is the "s" in comparison(s). That
confused me at first for a bit, because I thought I had read your link
already :)

I think that link for 9.24 could be much better chosen.
row-array-comparisons.html would match the content.

Best

Wolfgang

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2020-11-05 14:15:45 Re: BUG #16702: inline code and function : when use dynamic name for rowtype, there is some bug!
Previous Message Pavel Borisov 2020-11-05 13:48:23 Re: Wrong result for comparing ROW(...) with IS NOT NULL