On 04/14/10 08:33, Feixiong Li wrote:
> Hi , guys ,
>
> I am newbie for sql, I have a problem when using max() function, I need
> get null when there are null in the value list, or return the largest
> value as usual, who can do this?
>
> i.e. max([1,2,3,4,5]) => 5
> max([1,2,3,4,5,null]) => null
if u want a function, not an aggregate
then u have the
greatest(...)
except it does not return null on null input
(i was really surprised with this completely perverted behavior
(very unusual for postgres), but it is a fact)
if u want to cheat u may just
coalesce() each input argument
then nullif() a result of the greatest() function
(if only u have enough space in a reference range to room the one
special value instead of null)