Re: BUG #18999: Equivalent queries processing WHERE IS NULL & WHERE IS NOT NULL produce mutually exclusive results - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #18999: Equivalent queries processing WHERE IS NULL & WHERE IS NOT NULL produce mutually exclusive results
Date
Msg-id 1856868.1753450099@sss.pgh.pa.us
Whole thread Raw
In response to BUG #18999: Equivalent queries processing WHERE IS NULL & WHERE IS NOT NULL produce mutually exclusive results  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18999: Equivalent queries processing WHERE IS NULL & WHERE IS NOT NULL produce mutually exclusive results
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> I think "SELECT COUNT(c0) FROM t0" = "SELECT COUNT(c0) FROM t0 WHERE c0 IS
> NOT NULL" + "SELECT COUNT(c0) FROM t0 WHERE c0 IS NULL".

This is not so when c0 is composite.  Per [1]:

    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.

Pretty weird, I agree, but that's what the SQL standard
says to do.

            regards, tom lane

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



pgsql-bugs by date:

Previous
From: Hugo DUBOIS
Date:
Subject: Re: Unexpected Standby Shutdown on sync_replication_slots change
Next
From: Nathan Bossart
Date:
Subject: Re: BUG #18964: `ALTER DATABASE ... RESET ...` fails to reset extension parameters that no longer exist