Re: entering empty value - Mailing list pgsql-general

From Tom Lane
Subject Re: entering empty value
Date
Msg-id 5820.1014272109@sss.pgh.pa.us
Whole thread Raw
In response to Re: entering empty value  ("Gregory Wood" <gregw@com-stock.com>)
List pgsql-general
"Gregory Wood" <gregw@com-stock.com> writes:
> Actually, to be anal, a NULL value is used to denote an undefined or unknown
> value. If the value is known to be empty (and assuming this is stored in a
> string field such as TEXT or VARCHAR), it might be more appropriate to say:

> insert into t values (1,'');

Indeed, it seems that a frequent novice error is to confuse NULL with a
zero-length string.  They are completely different concepts; the sooner
you grasp that, the happier you'll be in working with SQL.  As Greg
says, NULL is best considered a placeholder indicating "value unknown"
or "value not present".  It is *never* equivalent to *any* legitimate
value of a datatype domain.

> This is especially true as empty strings can be used in an index, while NULL
> values, to the best of my knowledge, do not appear in indexes.

Postgres' btree indexes do index nulls.  However, at present this is at
best an academic curiosity, because our index access method API doesn't
provide any way to use an index to search for nulls.  (Technically,
"foo IS NULL" isn't an indexable operator.)  Fixing that is on the
might-happen-someday list.  In the meantime, it's best not to design
your data conventions in a way that requires you to search for nulls
often...

            regards, tom lane

pgsql-general by date:

Previous
From: "Gregory Wood"
Date:
Subject: Re: entering empty value
Next
From: Oliver Elphick
Date:
Subject: Re: deleting an identical record