Re: How to max() make null as biggest value?

From: silly sad <sad(at)bankir(dot)ru>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to max() make null as biggest value?
Date: 2010-04-21 07:43:06
Message-ID: 4BCEAC8A.80208@bankir.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas BOURIMECH 2010-04-21 09:06:25 LEFT OUTER JOIN issue
Previous Message Pavel Stehule 2010-04-20 17:02:21 Re: How to max() make null as biggest value?