Null Versus None

Any sufficiently complicated SQL database query contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of a Domain None on top of SqlNull. -- GreenLuxSpesTop? Tenth Rule Of Database Queries


None means Nothing, Nothing is a concept that describes the absence of anything at all. Nothing is sometimes confused with Null, but they are very different concepts because Nothing means absence of anything, while Null means unknown (you do not know if there is a thing or not).

For Nothing, the normal TwoValuedLogic applies (Nothing=Nothing : true, Nothing = Something : false), for Null, ThreeValuedLogic is necessary. Unfortunately, these 2 concepts have been used interchangeably without much thought, to point where the most common use for Null in relational databases is to mean Nothing (even when Null was designed to represent unknown by Codd). This confusion is aggravated by the fact that many mainstream application languages (Java, CSharp, Cee, etc) use the null keyword to mean uninitialized variable which easily maps to the interpretation that null means the variable is pointing to "nothing" (no object).

But for databases, Null was not invented to represent nothingness, was invented to represent that the value of something was not known (maybe be something, maybe nothing, we just do not know). See SqlNull for more on the origin of Null for databases.

Now that ChrisDate wants Null to be removed from RelationalDatabases, so that the incongruence and confusion brought in by ThreeValuedLogic is eliminated, the developers, accustomed to use Null to represent Nothing, resist to the idea asking: How am I going to represent the fact that a Person is not married? I use to do that by marking the MarriageDate? as a nullable Date. Now what? I need to split the table into 2 tables just to represent the fact that the MarriageDate? is not mandatory? That of course seems like the obvious, elegant (if extremely cumbersome answer). But the practical developer refuses to get into that trouble, it is just too much effort, it is simple easier to continue using Null. But... what about Nothing? why not just simply add "Nothing" as a possible value for to the Date domain? That way it is possible to say that the Person has no MarriageDate?, and still stay inside the realm of TwoValuedLogic.

Other Domains:

How about others?

Is this solution, in any way in conflict with TheThirdManifesto?


Real-world reports have Nulls, or at least "empty cells" and that's the way the customer wants them and will fire you if you don't deliver or spend too much time working around that gap.

Mmmm, and will they fire you when the queries using ThreeValuedLogic end up giving your customer the wrong information? (Also, most users I have met do not like empty cells in reports, because it is hard to tell if the value in there is unknown to the system, known but empty, or just a report error, they prefer some standard way of saying "I don't know what goes in here" or "there is no value for this" like the String "N/A"). -- LuxSpes

        Prod-ID Product        Cancellation Date
        ----------------------------------------
        1234    Fooz Ball      (not cancld. yet)
        2345    Teeth Cleaner     12/01/2008

Discussed Continued at SqlFlawsDiscussion.


Discussion from A better Null or replacement to Null (NullVersusNone) at HowOtherQueryLanguagesAddressSqlFlaws .

                   TYPE Date UNION;
                   TYPE ValidDate IS {Date POSSREP {Year INTEGER, Month INTEGER, Day INTEGER}};
                   TYPE NotExpiredYetDate IS {Date POSSREP {}};
                   TYPE MissingDate IS {Date POSSREP {Reason CHARACTER}};
.


See also AddingNoneForTypesInRel, SqlNull, ExBaseRant, GreenspunsTenthRuleOfProgramming

MarchTen


EditText of this page (last edited May 14, 2010) or FindPage with title or text search