Re: Sorting Issue

From: "Edward W(dot) Rouse" <erouse(at)comsquared(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Sorting Issue
Date: 2011-05-10 16:57:01
Message-ID: 064c01cc0f33$48216a80$d8643f80$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Looks like the sort is removing the spaces before sorting.

cxh
cxlm
cxlp
etc...

Edward W. Rouse

-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
On Behalf Of Ozer, Pam
Sent: Monday, May 09, 2011 3:39 PM
To: emilu(at)encs(dot)concordia(dot)ca
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Sorting Issue

That works. Why?

-----Original Message-----
From: Emi Lu [mailto:emilu(at)encs(dot)concordia(dot)ca]
Sent: Monday, May 09, 2011 12:38 PM
To: Ozer, Pam
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Sorting Issue

> I have the following query
>
> Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId
>
> from VehicleTrimAbbreviated
>
> Where vehicleTrimAbbreviated like 'CX%'
>
> order by VehicleTrimAbbreviated asc
>
> Results:
>
> 532;"CX Hatchback"
>
> 536;"CXL Minivan"
>
> 3255;"CXL Premium Sedan"
>
> 537;"CXL Sedan"
>
> 538;"CXL Sport Utility"
>
> 3319;"CXL Turbo Sedan"
>
> 533;"CX Minivan"
>
> 1959;"CX Plus Minivan"
>
> 534;"CX Sedan"
>
> 535;"CX Sport Utility"
>
> 539;"CXS Sedan"
>
> Why would this not sort correctly? All the CX should be first, then
CXL,
> Then CXS

Would you mind try:

Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId
from VehicleTrimAbbreviated
Where vehicleTrimAbbreviated like 'CX%'
order by

split_part(VehicleTrimAbbreviated, ' ', 1) asc,
split_part(VehicleTrimAbbreviated, ' ', 2) asc;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma 2011-05-10 17:16:21 Re: Dates and NULL's`
Previous Message John Fabiani 2011-05-10 16:48:41 Dates and NULL's`