Re: Specifying text to substitute for NULLs in selects

Поиск
Список
Период
Сортировка
От Mike Toews
Тема Re: Specifying text to substitute for NULLs in selects
Дата
Msg-id 4914B3FD.8070001@sfu.ca
обсуждение исходный текст
Ответ на Re: Specifying text to substitute for NULLs in selects  (Said Ramirez <sramirez@vonage.com>)
Ответы Re: Specifying text to substitute for NULLs in selects  (Mike Toews <mwtoews@sfu.ca>)
Список pgsql-general
Said Ramirez wrote:
> I think you are more after something like
>
> SELECT CASE WHEN foo IS NULL THEN 'NA' END FROM bar.
>   -Said

An even simpler way to do this is using the COALESCE function:
http://www.postgresql.org/docs/current/interactive/functions-conditional.html

SELECT COALESCE(foo, 'NA') AS foo FROM bar;

will either return the value in the field(s) "foo" or 'NA' if it is
NULL. Keep in mind that you can't mix data types, like 'NaN'::text and
32.3::float in the result.

-Mike

В списке pgsql-general по дате отправления:

Предыдущее
От: Ivan Sergio Borgonovo
Дата:
Сообщение: Re: Specifying text to substitute for NULLs in selects
Следующее
От: Jason Long
Дата:
Сообщение: archive command Permission Denied?