Re: LEAST and GREATEST functions?

Поиск
Список
Период
Сортировка
От Stefan Bill
Тема Re: LEAST and GREATEST functions?
Дата
Msg-id 20030701045445.80319.qmail@web13905.mail.yahoo.com
обсуждение исходный текст
Ответ на Re: LEAST and GREATEST functions?  (Josh Berkus <josh@agliodbs.com>)
Список 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 по дате отправления:

Предыдущее
От: Joe Conway
Дата:
Сообщение: Re: LEAST and GREATEST functions?
Следующее
От: "Alon Noy"
Дата:
Сообщение: passing a record as a function argument in pl/pgsql