Re: min() and NaN

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: min() and NaN
Дата
Msg-id 19874.1058676022@sss.pgh.pa.us
обсуждение исходный текст
Ответ на min() and NaN  ("Michael S. Tibbetts" <mtibbetts@head-cfa.harvard.edu>)
Ответы Re: min() and NaN  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список pgsql-sql
"Michael S. Tibbetts" <mtibbetts@head-cfa.cfa.harvard.edu> writes:
> 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'.

Not real surprising given than min() is implemented with float8smaller,
which does this:
result = ((arg1 > arg2) ? arg1 : arg2);

In most C implementations, any comparison involving a NaN will return
"false".  So when we hit the NaN, we have arg1 = min so far, arg2 = NaN,
comparison yields false, result is NaN.  On the next row, we have
arg1 = NaN, arg2 = next value, comparison yields false, result is next
value; and away it goes.

We could probably make it work the way you want with explicit tests for
NaN in float8smaller, arranged to make sure that the result is not NaN
unless both inputs are NaN.  But I'm not entirely convinced that we
should make it work like that.  The other float8 comparison operators
are designed to treat NaN as larger than every other float8 value (so
that it has a well-defined position when sorting), and I'm inclined to
think that float8smaller and float8larger probably should behave
likewise.  (That actually is the same as what you want for MIN(), but
not for MAX() ...)

Comments anyone?
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: column doesn't get calculated - updated
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: min() and NaN