Re: LEAST and GREATEST functions? - Mailing list pgsql-sql

From Greg Stark
Subject Re: LEAST and GREATEST functions?
Date
Msg-id 87d6gu2otf.fsf@stark.dyndns.tv
Whole thread Raw
In response to Re: LEAST and GREATEST functions?  (Josh Berkus <josh@agliodbs.com>)
Responses Re: LEAST and GREATEST functions?  (Bruno Wolff III <bruno@wolff.to>)
Re: LEAST and GREATEST functions?  (Joe Conway <mail@joeconway.com>)
Re: LEAST and GREATEST functions?  (Ang Chin Han <angch@bytecraft.com.my>)
List pgsql-sql
Josh Berkus <josh@agliodbs.com> writes:

> Stefan,
> 
> > I know the LEAST and GREATEST functions are not part
> > of standard SQL, but they sure were handy where I came
> > from (Oracle-land).
> 
> Um, what's wrong with MAX and MIN, exactly?

MAX and MIN are single-parameter aggregate functions. LEAST and GREATEST are
two-parameter (though in postgres they could be defined for 3 and more
parameters) scalar functions.

eg:

SELECT max(a) FROM bar 

would return a single tuple with the maximum value of a from amongst every
record. whereas:

SELECT greatest(a,b) FROM bar

would return one tuple for every record in the table with a single value
representing the greater of bar.a and bar.b.

You could define your own functions to do this but it would be tiresome to
define one for every datatype.

-- 
greg



pgsql-sql by date:

Previous
From: Robert Treat
Date:
Subject: Re: Immutable attributes?
Next
From: Matthew Hixson
Date:
Subject: Re: need some help with a delete statement