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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Feixiong Li <feixiongli(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to max() make null as biggest value?
Date: 2010-04-20 15:17:53
Message-ID: s2z162867791004200817j80b0a976u9979bfc7e7d73f25@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello

2010/4/14 Feixiong Li <feixiongli(at)gmail(dot)com>:
> 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?
>

max() returns max value of some column

create table foo(a int);
insert into foo values(10);
insert into foo values(33);

postgres=# select * from foo;
a
----
10
33
(2 rows)

Time: 0,524 ms
postgres=# select max(a) from foo;
max
-----
33
(1 row)

there is function greatest

postgres=# select greatest(1,2,34,2,1);
greatest
----------
34
(1 row)

regards
Pavel Stehule

> i.e.  max([1,2,3,4,5]) => 5
> max([1,2,3,4,5,null]) => null
>
> thanks in advance!
>
> Feixiong
> feixiongli(at)gmail(dot)com
>
>
>
>
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros 2010-04-20 15:30:49 Re: How to max() make null as biggest value?
Previous Message Steve Lefevre 2010-04-20 14:51:59 creating a versioning system for sets?