From: Stefan Bill <sjb26@yahoo.com>
To: Josh Berkus <josh@agliodbs.com>
To: pgsql-sql@postgresql.org
Subject: Re: LEAST and GREATEST functions?
Date: Mon, 30 Jun 2003 21:54:45 -0700 (PDT)
Message-ID: <20030701045445.80319.qmail@web13905.mail.yahoo.com> (raw)
In-Reply-To: <200306302032.23113.josh@agliodbs.com>
> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sjb26@yahoo.com, josh@agliodbs.com
Subject: Re: LEAST and GREATEST functions?
In-Reply-To: <20030701045445.80319.qmail@web13905.mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox