Skip site navigation (1) Skip section navigation (2)

Re: Greatest/Least functions?

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: Karsten(dot)Hilbert(at)gmx(dot)net (Karsten Hilbert),pgsql-general(at)postgresql(dot)org (pgsql general list)
Subject: Re: Greatest/Least functions?
Date: 2004-08-22 17:35:20
Message-ID: 200408221735.i7MHZLWv009715@gw.tssi.com (view raw or flat)
Thread:
Lists: pgsql-general
> > As far as I can tell, Postgres has no equivalent to greatest and least
> > functions in Oracle.
> Doesn't max/min() do that ? Note that I know nothing about
> greatest/least in Oracle.

No, max/min are aggregate functions.  Greatest allows you to select
the largest of a series of terms.

Here's a simple example:

greatest(1,2,3,4,5,6) would return 6

Here's a bit more useful one:

greatest(field1,field2,field3) would return the largest value from the 
three supplied fields from the current row.  

Writing a case statement to select the largest from among 3 or more 
values gets a bit complicated.
--
Mike Nolan

In response to

Responses

pgsql-general by date

Next:From: Tom LaneDate: 2004-08-22 17:37:29
Subject: Re: About inheritance
Previous:From: Joe ConwayDate: 2004-08-22 17:32:32
Subject: Re: Greatest/Least functions?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group