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

From Stefan Bill
Subject Re: LEAST and GREATEST functions?
Date
Msg-id 20030701045445.80319.qmail@web13905.mail.yahoo.com
Whole thread Raw
In response to Re: LEAST and GREATEST functions?  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
> Um, what's wrong with MAX and MIN, exactly?

MIN and MAX are aggregate functions, LEAST and
GREATEST are not.  See the examples on the following
table:

foo
A B
- -
1 4
2 3
3 2

> SELECT LEAST(a, b), GREATEST(a, b) FROM foo;

LEAST(a, b) GREATEST(a, b)
----------- --------------
1           4
2           3
2           3

> SELECT MIN(a), MAX(b) FROM foo;

MIN(a) MAX(b)
------ ------
1      4

After further research, I found that the only way to
have a function with a variable number of arguments is
to create N number of overloaded functions, e.g.
CREATE FUNCTION least(int)...
CREATE FUNCTION least(int, int)...
CREATE FUNCTION least(int, int, int)...
...etc...

That sucks, especially since the underlying languages
support variable arguments that will scale to
who-knows-where (see varargs in C, *args in Python,
for starters).  Not only that, but I'd have to create
another N number of functions for different datatypes
(int, float, date, etc.).

In addition to adding the LEAST and GREATEST
functions, the PostgreSQL developers should add the
ability to create user-defined functions with a
variable number of arguments.

Cheers,

-Stefan


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com


pgsql-sql by date:

Previous
From: Joe Conway
Date:
Subject: Re: LEAST and GREATEST functions?
Next
From: "Alon Noy"
Date:
Subject: passing a record as a function argument in pl/pgsql