Re: Nulls get converted to 0 problem

From: Erik Ronström <kvarken(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Nulls get converted to 0 problem
Date: 2003-06-06 23:14:02
Message-ID: 20030606231402.10656.qmail@web13802.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--- Jon Earle <je_pgsql(at)kronos(dot)honk(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brian Avis 2003-06-07 00:09:03 Backups and restores.
Previous Message DeJuan Jackson 2003-06-06 22:46:11 Re: Nulls get converted to 0 problem