Re: How to max() make null as biggest value? - Mailing list pgsql-sql

From silly sad
Subject Re: How to max() make null as biggest value?
Date
Msg-id 4BCEAC8A.80208@bankir.ru
Whole thread Raw
In response to How to max() make null as biggest value?  (Feixiong Li <feixiongli@gmail.com>)
List pgsql-sql
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)





pgsql-sql by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: How to max() make null as biggest value?
Next
From: Thomas BOURIMECH
Date:
Subject: LEFT OUTER JOIN issue