pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: lynch@lscorp.com
To: pgsql-sql@postgresql.org
Subject: Smallest/Largest String in column
Date: Wed, 24 Jun 1998 16:54:58 -0500
Message-ID: <v02140b59b1b6dc9d3a19@[207.152.64.133]> (raw)

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





Message-ID: <v02140b59b1b6dc9d3a19@[207.152.64.133]>
Permalink:  ../v02140b59b1b6dc9d3a19@%5B207.152.64.133%5D/
Also on:    postgresql.org/message-id/v02140b59b1b6dc9d3a19@[207.152.64.133]

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: lynch@lscorp.com
  Subject: Re: Smallest/Largest String in column
  In-Reply-To: <v02140b59b1b6dc9d3a19@[207.152.64.133]>
  References: <v02140b59b1b6dc9d3a19@[207.152.64.133]>

* 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