Databasen - NULL dates

Ovid publiustemp-londonpm at
Fri Oct 20 20:00:39 BST 2006

--- Jess Robinson <castaway at> wrote:
> >  select,
> >  from   orders o, invoices i
> >  where = i.order_id
> >    and  ( <> or <> '25122007' );
> >
> [ snip explanation]
> I'd call that a spurious example, the question was for "unknown
> dates", if 
> you're creating a system of invoices, and you expect the dates to be 
> unknown at some point, something is very wrong. I would expect anyone

> designing the thing to a) know when to set nullable, and when not,
> and b) 
> set it on purpose, and thus also have it in mind when they're
> creating such queries..

Except ... that query gives a logically incorrect answer.  Go ahead and
rename those columns and business rules any way you want to until you
can call the dates "unknown".  That SQL will still give a logically
incorrect answer.

NULLs in databases lead to problems like this.  What's worse is when
you return thousands of rows of data and only have a handful which are
incorrectly excluded.  The problem might very well go undetected. 
NULLs should only be used with great caution.  People are quite
cavalier about their use and happily throw them in any ol' table just
because it's easier than figuring out the underlying problem
(disclaimer:  I've done the same thing, so "je m'accuse").



Buy the book --
Perl and CGI --

More information about the mailing list