Re: Specifying text to substitute for NULLs in selects

From: Mike Toews <mwtoews(at)sfu(dot)ca>
To: Said Ramirez <sramirez(at)vonage(dot)com>
Cc: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>, pgsql-general(at)postgresql(dot)org
Subject: Re: Specifying text to substitute for NULLs in selects
Date: 2008-11-07 22:04:53
Message-ID: 4914BB85.60400@sfu.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Toews wrote:
> Keep in mind that you can't mix data types, like 'NaN'::text and
> 32.3::float in the result.

oh yeah, regarding mixing data types (in regards to the first post)...

A good exception is that you can use 'NaN' for floating point data
types, so:

SELECT COALESCE(myval, 'NaN') as myval FROM foo;

where "myval" is a field with a floating-point data type. This maneuver
is sometimes preferred in some aggregates like sum() where you don't
want to take sums on incomplete sets since NULL is counted as 0 whereas
a single NaN value forces the resulting sum to be NaN.

There are other special floats like 'Infinity' and '-Infinity', which
can also be coalesced in for NULL float values:
http://www.postgresql.org/docs/current/interactive/datatype-numeric.html

-Mike

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-11-07 22:14:33 Re: archive command Permission Denied?
Previous Message Jason Long 2008-11-07 21:55:20 archive command Permission Denied?