From: | Stefan Bill <sjb26(at)yahoo(dot)com> |
---|---|
To: | Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: LEAST and GREATEST functions? |
Date: | 2003-07-01 04:54:45 |
Message-ID: | 20030701045445.80319.qmail@web13905.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Matthew Hixson | 2003-07-01 08:24:04 | Re: need some help with a delete statement |
Previous Message | Stephan Szabo | 2003-07-01 04:49:30 | Re: CREATE SEQUENCE fails in plpgsql function |