X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A3248310BA5 for ; Tue, 1 Jul 2003 04:54:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 69215-08 for ; Tue, 1 Jul 2003 01:54:47 -0300 (ADT) Received: from web13905.mail.yahoo.com (web13905.mail.yahoo.com [216.136.175.68]) by svr1.postgresql.org (Postfix) with SMTP id 78323310BA4 for ; Tue, 1 Jul 2003 01:54:46 -0300 (ADT) Message-ID: <20030701045445.80319.qmail@web13905.mail.yahoo.com> Received: from [207.138.106.50] by web13905.mail.yahoo.com via HTTP; Mon, 30 Jun 2003 21:54:45 PDT Date: Mon, 30 Jun 2003 21:54:45 -0700 (PDT) From: Stefan Bill Subject: Re: LEAST and GREATEST functions? To: Josh Berkus , pgsql-sql@postgresql.org In-Reply-To: <200306302032.23113.josh@agliodbs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200307/23 X-Sequence-Number: 14137 > 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