Re: entering empty value

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: entering empty value
Дата
Msg-id 5820.1014272109@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: entering empty value  ("Gregory Wood" <gregw@com-stock.com>)
Список 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 по дате отправления:

Предыдущее
От: "Gregory Wood"
Дата:
Сообщение: Re: entering empty value
Следующее
От: Oliver Elphick
Дата:
Сообщение: Re: deleting an identical record