Re: Sorting Issue - Mailing list pgsql-sql

From Ozer, Pam
Subject Re: Sorting Issue
Date
Msg-id 216FFB77CBFAEE4B8EE4DF0A939FF1D14F85F8@mail-001.corp.automotive.com
Whole thread Raw
In response to Re: Sorting Issue  (Emi Lu <emilu@encs.concordia.ca>)
Responses Re: Sorting Issue  (Emi Lu <emilu@encs.concordia.ca>)
List pgsql-sql
Ok but why doesn't the other way work?  I can't use the function in my
query. It is dynamically created.

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


> That works. Why?

http://www.postgresql.org/docs/current/static/functions-string.html


split_part(string text, delimiter text, field int)    text    Split
string on
delimiter and return the given field (counting from one)
split_part('abc~@~def~@~ghi', '~@~', 2)    def

Emi


> -----Original Message-----
> From: Emi Lu [mailto:emilu@encs.concordia.ca]
> Sent: Monday, May 09, 2011 12:38 PM
> To: Ozer, Pam
> Cc: pgsql-sql@postgresql.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;
>
>


pgsql-sql by date:

Previous
From: Emi Lu
Date:
Subject: Re: Sorting Issue
Next
From: Emi Lu
Date:
Subject: Re: Sorting Issue