Re: Sorting Issue

From: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
To: emilu(at)encs(dot)concordia(dot)ca
Cc: "Ozer, Pam" <pozer(at)automotive(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Sorting Issue
Date: 2011-05-09 21:08:41
Message-ID: BANLkTikJhPpiM-rV9DX1rp_1dJhbTGOtZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, May 9, 2011 at 1:38 PM, Emi Lu <emilu(at)encs(dot)concordia(dot)ca> wrote:

> Hi Pam,
>
>
> >> Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId
> >> from VehicleTrimAbbreviated
> >> Where vehicleTrimAbbreviated like 'CX%'
> >> order by
> >>
> >> split_part(VehicleTrimAbbreviated, ' ', 1) asc,
> >> split_part(VehicleTrimAbbreviated, ' ', 2) asc;
>
> This query works, right?
>
> Reason:
> ======
> . split_part(VehicleTrimAbbreviated, ' ', 1) return the string before the
> blank
>
> . split_part(VehicleTrimAbbreviated, ' ', 1) return the string after the
> blank
>
> So
> [1] you order by CX, CXL, CXS first
> [2] you order by second part "Hatchback, Minivan... "
>
> Is there clear now?
>
>
Not really. It should sort alphabetically the same in either case. Here's
an alphabetic sort of similar strings in python

>>> a = ["CX Hatchback", "CXL Minivan", "CXL Premium Sedan", "CXL Sedan",
"CXL Sport Utility", "CXL Turbo Sedan", "CX Minivan", "CXS Sedan"]
>>> a.sort()
>>> a
['CX Hatchback', 'CX Minivan', 'CXL Minivan', 'CXL Premium Sedan', 'CXL
Sedan', 'CXL Sport Utility', 'CXL Turbo Sedan', 'CXS Sedan']

It's not at all clear why they are not coming out of the db in
alphabetically sorted order when the query includes "order by
VehicleTrimAbbreviated asc"

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2011-05-09 21:28:34 Re: Sorting Issue
Previous Message Emi Lu 2011-05-09 20:38:36 Re: Sorting Issue