Received: from lscorp.com (poohbah.lscorp.com [207.152.64.2]) by hub.org (8.8.8/8.7.5) with ESMTP id RAA23629 for ; Wed, 24 Jun 1998 17:56:51 -0400 (EDT) Received: from [207.152.64.133] by lscorp.com with SMTP (Eudora Internet Mail Server 1.2); Wed, 24 Jun 1998 16:54:58 -0500 X-Sender: lynch@poohbah.lscorp.com Message-Id: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: pgsql-sql@postgresql.org From: lynch@lscorp.com (Richard Lynch) Subject: Smallest/Largest String in column Date: Wed, 24 Jun 1998 16:54:58 -0500 I need an SQL aggregate (or typecasting or function or whatever) that will find the smallest item in a column of type text. Actually, I need min/max from each of 4 columns of type text. That would be 8 total. *ACTUALLY*, I need the smallest/largest from all of *those*, but I reckon it would be a bit much to ask SQL to do that in one shot... or maybe not. I'd much rather do: "select min(lastname), max(lastname, min(firstname), max(firstname), min(business), max(business), min(band), max(band) from members;" than the 8 selects that would otherwise be required, since I suspect it will be a mite faster. 'Course, there's only a 130 rows now, and it will only end up being 1000 or so in the end, I think... Alas, the docs about aggregates don't exactly inspire me to think I can handle this on my own, and I couldn't find it in the archives... Anybody done this before... or do I have to use a lot of skull sweat to figure out aggregates and functions and builtin types and primitives and extensibility? See, I *read* the manual, I just didn't understand it too well. :-) THANKS! PS Do I wanna try to overload the min/max aggregates, or would that be a definite no-no? PPS As far as case-sensitivity goes... I guess I want to do whatever ORDER BY does, unless there's some way to make that case-insensitive I haven't learned yet. In the ideal world, everything would be case-insensitive... In the real world, I'm stuck with whatever of "ORDER BY" and "where blah >= 'A'" can be convinced to do. -- -- -- "TANSTAAFL" Rich lynch@lscorp.com