From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Michael S(dot) Tibbetts" <mtibbetts(at)head-cfa(dot)cfa(dot)harvard(dot)edu>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: min() and NaN |
Date: | 2003-07-20 06:26:28 |
Message-ID: | 20030719232158.H55138-100000@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Sun, 20 Jul 2003, Tom Lane wrote:
> "Michael S. Tibbetts" <mtibbetts(at)head-cfa(dot)cfa(dot)harvard(dot)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() ...)
The spec seems to say that min/max should work the same way as the
comparison operators by saying that it returns the maximum or minimum
value as determined by the comparison rules of the comparison predicate
section. That'd seem to be asking for the second version.
From | Date | Subject | |
---|---|---|---|
Next Message | Oleg Bartunov | 2003-07-20 07:44:49 | Re: Join table with itself for heirarchial system? |
Previous Message | Stephan Szabo | 2003-07-20 06:20:00 | Re: Return a set of values from postgres Function |