pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Samuel Gendler <sgendler@ideasculptor.com>
To: emilu@encs.concordia.ca
Cc: Ozer, Pam <pozer@automotive.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sorting Issue
Date: Mon, 9 May 2011 14:08:41 -0700
Message-ID: <BANLkTikJhPpiM-rV9DX1rp_1dJhbTGOtZQ@mail.gmail.com> (raw)
In-Reply-To: <4DC850CC.50409@encs.concordia.ca>
References: <216FFB77CBFAEE4B8EE4DF0A939FF1D14F85F1@mail-001.corp.automotive.com>
	<4DC84284.4000903@encs.concordia.ca>
	<216FFB77CBFAEE4B8EE4DF0A939FF1D14F85F7@mail-001.corp.automotive.com>
	<4DC845EC.1020806@encs.concordia.ca>
	<216FFB77CBFAEE4B8EE4DF0A939FF1D14F85F8@mail-001.corp.automotive.com>
	<4DC850CC.50409@encs.concordia.ca>

On Mon, May 9, 2011 at 1:38 PM, Emi Lu <emilu@encs.concordia.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"

view thread (17+ messages)  latest in thread

Message-ID: <BANLkTikJhPpiM-rV9DX1rp_1dJhbTGOtZQ@mail.gmail.com>
Permalink:  ../BANLkTikJhPpiM-rV9DX1rp_1dJhbTGOtZQ@mail.gmail.com/
Also on:    postgresql.org/message-id/BANLkTikJhPpiM-rV9DX1rp_1dJhbTGOtZQ@mail.gmail.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sgendler@ideasculptor.com, emilu@encs.concordia.ca, pozer@automotive.com
  Subject: Re: Sorting Issue
  In-Reply-To: <BANLkTikJhPpiM-rV9DX1rp_1dJhbTGOtZQ@mail.gmail.com>

* 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