From: | lynch(at)lscorp(dot)com (Richard Lynch) |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Smallest/Largest String in column |
Date: | 1998-06-24 21:54:58 |
Message-ID: | v02140b59b1b6dc9d3a19@[207.152.64.133] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)lscorp(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Jeffrey Lyon | 1998-06-25 12:21:08 | problem w/ DELETE |
Previous Message | Mariana Travassos Aguiar da Silva | 1998-06-24 21:03:16 | Help |