Search Postgresql Archives

Re: Specifying text to substitute for NULLs in selects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux