Re: min() and NaN

Stephan Szabo <sszabo@megazone.bigpanda.com>

From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: "Michael S. Tibbetts" <mtibbetts@head-cfa.harvard.edu>
Cc: <pgsql-sql@postgresql.org>
Date: 2003-07-20T06:11:34Z
Lists: pgsql-sql
On Tue, 15 Jul 2003, Michael S. Tibbetts wrote:

> Hi,
>
> I have a table containing a double precision column. That column
> contains at least one judiciously placed NaN.
>
> I'd expect the aggregate function min() to return the minimum, valid
> numeric value.  Instead, it seems to return the minimum value from the
> subset of rows following the 'NaN'.

This appears to be a bug in the min (and presumably max) aggregate
function for floats.  AFAICT It should use the same logic as the < (or >)
comparison operator for the type (SQL92 6.5 GR2b iii I believe), but it's
just doing a < (or >) in C on the two arguments which isn't the same.

Changing it to follow those rules would give 2.718 for min and it looks
like NaN for max.