pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jinhui-lai@foxmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18999: Equivalent queries processing WHERE IS NULL & WHERE IS NOT NULL produce mutually exclusive results
Date: Fri, 25 Jul 2025 09:28:19 -0400
Message-ID: <1856868.1753450099@sss.pgh.pa.us> (raw)
In-Reply-To: <18999-4dbdbaeafb1c1023@postgresql.org>
References: <18999-4dbdbaeafb1c1023@postgresql.org>

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





view thread (5+ messages)  latest in thread

Message-ID: <1856868.1753450099@sss.pgh.pa.us>
Permalink:  ../1856868.1753450099@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1856868.1753450099@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jinhui-lai@foxmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18999: Equivalent queries processing WHERE IS NULL & WHERE IS NOT NULL produce mutually exclusive results
  In-Reply-To: <1856868.1753450099@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox