Re: Nulls get converted to 0 problem

From: Jonathan Bartlett <johnnyb(at)eskimo(dot)com>
To: kdebisschop(at)alert(dot)infoplease(dot)com
Cc: Jon Earle <je_pgsql(at)kronos(dot)honk(dot)org>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Nulls get converted to 0 problem
Date: 2003-06-06 15:17:37
Message-ID: Pine.GSU.4.44.0306060815280.22643-100000@eskimo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I think the basic idea is that NULL can be used for purposes outside the
normal range of numbers.

For example, I can use NULL to indicate that I don't know what the value
is, as apposed to the value actually being 0.

This would be better accomplished by fuller support for value domains, but
no database (or few unknown ones) implement that, and NULL is the next
best thing.

Jon

On 6 Jun 2003 kdebisschop(at)alert(dot)infoplease(dot)com wrote:

> On Thu, 2003-06-05 at 09:39, Jon Earle wrote:
> > On Wed, 4 Jun 2003 terry(at)ashtonwoodshomes(dot)com wrote:
> >
> > > Oracle *incorrectly* interprets blank (empty) strings as NULL. They are NOT
> > > the same. A string of zero characters is a string nonetheless. A NULL is
> > > "the absence of value", which equals nothing (theoretically not even another
> > > NULL).
> >
> > 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?
> >
> > 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?
>
> Perhaps because the SQL Spec says they are different?
>
> For that matter, a zero length string in C is not the same as NULL.
> Believing otherwise may be convenient, but leads to segfaults
>
> i.e., this code will cause a segfault
>
> main(...) {
> char *str;
>
> if (str == NULL)
> printf ("This test is safe\n");
>
> if (str == "")
> printf ("This comparison above can segfault on some systems\n");
>
> printf ("printing a NULL string like %s can also segfault\n", str);
>
> }
>
> I believe in C the following is true as well:
>
> main() {
> char *str="";
>
> if (str)
> printf ("An empty string evaluates as true");
>
> }
>
> --
> Karl DeBisschop <kdebisschop(at)alert(dot)infoplease(dot)com>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rory Campbell-Lange 2003-06-06 15:20:01 Return Record
Previous Message Jon Earle 2003-06-06 15:17:01 Select from multiple tables