Library sort order (was Re: SQL command speed)

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: pgsql-sql(at)postgresql(dot)org
Subject: Library sort order (was Re: SQL command speed)
Date: 2000-05-18 22:03:18
Message-ID: 20000518170318.B2964@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Sorry about the subject: I meant to change it on the last one.

As usual, 5 minutes after posting, I came up with a solution, at least
for my limited case of ignoring an inital 'The ':

SELECT InstName FROM Institutions ORDER BY CASE WHEN
strpos(InstName,'The ') = 1 THEN ltrim(InstName,'The ') ELSE
InstName END;

Note that this requires 7.0, since 6.X won't allow a CASE node in the
ORDER BY position.

Ross

On Thu, May 18, 2000 at 03:39:09PM -0500, Ross J. Reedstrom wrote:
> Hey crew:
> I've got a relatively simple SQL problem. In a db backed web site
> we're building, I'd like to fill a dropdown box with the contents of a
> validation table, in this case research institutions. I want to sort them
> alphabetically, but using "library rules": i.e. skip inital articles,
> since we've a few 'The University of Foo" and "The Johns Hopkins
> University", for example.
>
> I thought I had it with this SQL:
>
> SELECT InstName from Institutions ORDER BY ltrim (InstName, 'The');
>
> Looked good, until I found 'Texas A&M University' sorting below York.
>
> Seems ltrim() removes inital charaters from the set of charaters, not
> inital strings, so I was sorting on 'xas A&M University'
>
> Anyone have some magic solution for this?
>
> Ross
> --
> Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu>
> NSBRI Research Scientist/Programmer
> Computer and Information Technology Institute
> Rice University, 6100 S. Main St., Houston, TX 77005
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message mkresse 2000-05-18 22:19:36 Re: Foreign keys and access privileges
Previous Message Stephan Szabo 2000-05-18 22:02:02 Re: SQL command speed