From: silly sad <sad@bankir.ru>
To: pgsql-sql@postgresql.org
Subject: Re: How to max() make null as biggest value?
Date: Wed, 21 Apr 2010 11:43:06 +0400
Message-ID: <4BCEAC8A.80208@bankir.ru> (raw)
In-Reply-To: <2A8BBCA2-814C-4E8D-BCE1-11FA2F8D120E@gmail.com>
References: <2A8BBCA2-814C-4E8D-BCE1-11FA2F8D120E@gmail.com>
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sad@bankir.ru
Subject: Re: How to max() make null as biggest value?
In-Reply-To: <4BCEAC8A.80208@bankir.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox