Re: Greatest/Least functions?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
Cc: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>, pgsql general list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Greatest/Least functions?
Date: 2004-08-23 13:29:08
Message-ID: 20040823132908.GC4765@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Aug 22, 2004 at 12:35:20PM -0500, Mike Nolan wrote:
> > > 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.

Postgresql does however have the 2-argument versions:

int4larger, int4smaller
floatlarger, floatsmaller

Not seen them mentioned much, but they're very useful... Of course,
after a while even:

int4larger( int4larger( field1, field2 ), int4larger( field3, field4 ) )

gets tiring.
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2004-08-23 13:35:38 Re: Catching server shutdown in C
Previous Message Oleg 2004-08-23 13:23:12 Re: problem with postgresql-dump while upgrading to 7.4