Re: Specifying text to substitute for NULLs in selects - Mailing list pgsql-general

From Mike Toews
Subject Re: Specifying text to substitute for NULLs in selects
Date
Msg-id 4914B3FD.8070001@sfu.ca
Whole thread Raw
In response to Re: Specifying text to substitute for NULLs in selects  (Said Ramirez <sramirez@vonage.com>)
Responses Re: Specifying text to substitute for NULLs in selects  (Mike Toews <mwtoews@sfu.ca>)
List 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 by date:

Previous
From: Ivan Sergio Borgonovo
Date:
Subject: Re: Specifying text to substitute for NULLs in selects
Next
From: Jason Long
Date:
Subject: archive command Permission Denied?