Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s206Q-00Ge8L-Rl for pgsql-bugs@arkaria.postgresql.org; Wed, 01 May 2024 02:53:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s206O-00ANGo-Ad for pgsql-bugs@arkaria.postgresql.org; Wed, 01 May 2024 02:53:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s206O-00ANGe-2U for pgsql-bugs@lists.postgresql.org; Wed, 01 May 2024 02:53:48 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s206M-000rjQ-Ik for pgsql-bugs@lists.postgresql.org; Wed, 01 May 2024 02:53:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4412rjNw1859815; Tue, 30 Apr 2024 22:53:45 -0400 From: Tom Lane To: David Rowley cc: "David G. Johnston" , Darryl Dixon , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #18451: NULL fails to coerce to string when performing string comparison In-reply-to: References: <18451-dc130ad59b7bd7c9@postgresql.org> <1825308.1714516246@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Wed, 01 May 2024 14:34:34 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1859813.1714532025.1@sss.pgh.pa.us> Date: Tue, 30 Apr 2024 22:53:45 -0400 Message-ID: <1859814.1714532025@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Wed, 1 May 2024 at 10:30, Tom Lane wrote: >> Yeah, there's a documentation gap here. I dug around a little and >> really couldn't find anything anywhere in our SGML docs that explains >> NULL in any detail; we tend to assume that you've already heard of it. > What is really generic enough about SQL NULLs to put somewhere > generic? I think the key points I'd want to get across include: * Any value can be NULL rather than a "normal" value of its datatype. * There are various ways to think about the meaning of NULL, but an often-useful viewpoint is that it represents an unknown value. * A majority of SQL operations, including nearly all built-in functions and operators, are strict meaning they yield NULL if any input is NULL. This is consistent with interpreting NULL as "unknown". Depending on how ambitious we wanted to be, we could add examples illustrating these points. For instance we could explain the behavior of the boolean operators (such as "true OR null => true", "true AND null => null") as being consistent with the "unknown" interpretation. Some of this material could be moved or copied from existing text. There is attraction in centralizing the treatment, but on the other hand those examples are all pretty on-point where they are. I wouldn't have a problem with being a bit repetitious, though. It's not like these facts are going to change and need updates. > I mean NULL = NULL is NULL rather than true, but NULLs are > treated as equal in DISTINCT and GROUP BY. It would not hurt to say that the SQL standard isn't 100% logically consistent about how it handles NULLs. But this particular point isn't that bad: we could introduce the definition of distinctness ("IS [NOT] DISTINCT FROM") and then say that grouping operations use that behavior rather than what "=" does. The bottom line is that I think nowadays a lot of people learn SQL from our documentation, rather than coming to our docs with pre-existing SQL knowledge. So we need to fill in these sorts of explanatory gaps. regards, tom lane