Re: Nulls get converted to 0 problem - Mailing list pgsql-general

From Erik Ronström
Subject Re: Nulls get converted to 0 problem
Date
Msg-id 20030606231402.10656.qmail@web13802.mail.yahoo.com
Whole thread Raw
In response to Re: Nulls get converted to 0 problem  (Jon Earle <je_pgsql@kronos.honk.org>)
List pgsql-general
 --- Jon Earle <je_pgsql@kronos.honk.org> wrote:
> If you're testing a value, you're testing to see if there's something
> in there or not - what difference does it make if the variable
> contains 0, "" or NULL?

Depends. Say you have a table of persons and want to store the number
of cars they own in a column. 0 would mean that a person doesn't own
any car, but a NULL value rather indicates that the number of cars is
unknown.

It's not very hard to come up with examples where you want to separate
empty strings and NULL values. The point is that "" could mean "there's
something in there - an empty string", compared to "there is nothing
there".

> Why not adhere to the practices inherent (and thus anticipated by
> developers) in other languages (C comes to mind) where 0, NULL and ""
> are equivalent?

Perl is an excellent example of a programming language that uses NULL
values ("undef") in clever ways.

"The C style" can be used with Perl, since both the undefined value,
the empty string and 0 evaluates to false. "The Perl style" cannot
easily be used in C. IMHO, that's a strong argument for the support of
undefined (NULL) values: you don't have to use them if you don't want
to (in SQL, just use NOT NULL to prohibit NULL values), but it's very
hard to simulate them if you really want to separate 0 and NULL.

Erik

__________________________________________________
Yahoo! Plus - For a better Internet experience
http://uk.promotions.yahoo.com/yplus/yoffer.html

pgsql-general by date:

Previous
From: "Ned Lilly"
Date:
Subject: MySQL gets $19.5 MM
Next
From: DeJuan Jackson
Date:
Subject: Re: Nulls get converted to 0 problem