pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6056: sorting issues
4+ messages / 3 participants
[nested] [flat]

* BUG #6056: sorting issues
@ 2011-06-13 21:52 Mike Hepworth <michael.w.hepworth@gmail.com>
  2011-06-14 06:44 ` Re: BUG #6056: sorting issues Itagaki Takahiro <itagaki.takahiro@gmail.com>
  2011-06-14 11:14 ` Re: BUG #6056: sorting issues hubert depesz lubaczewski <depesz@depesz.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Mike Hepworth @ 2011-06-13 21:52 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      6056
Logged by:          Mike Hepworth
Email address:      michael.w.hepworth@gmail.com
PostgreSQL version: 8.4
Operating system:   Ubuntu 10.4
Description:        sorting issues
Details: 

Have database that is utf-8 encoding so that I can support both english,
french, and spanish.  Having problems with the ordering of data.

I execute the following sql statment:

select * from (values('HALL, ANDY'),('HALLBERG, FRANK'),('HALLDEN,
DOUGLAS'),('HALL, DOUGLAS') ) x ORDER BY 1;

and get the following results

HALL, ANDY
HALLBERG, FRANK
HALLDEN, DOUGLAS
HALL, DOUGLAS

Please Help...



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #6056: sorting issues
  2011-06-13 21:52 BUG #6056: sorting issues Mike Hepworth <michael.w.hepworth@gmail.com>
@ 2011-06-14 06:44 ` Itagaki Takahiro <itagaki.takahiro@gmail.com>
  2011-06-14 13:42   ` Re: BUG #6056: sorting issues Itagaki Takahiro <itagaki.takahiro@gmail.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Itagaki Takahiro @ 2011-06-14 06:44 UTC (permalink / raw)
  To: Mike Hepworth <michael.w.hepworth@gmail.com>; +Cc: pgsql-bugs

On Tue, Jun 14, 2011 at 06:52, Mike Hepworth
<michael.w.hepworth@gmail.com> wrote:
> Bug reference:      6056
> Logged by:          Mike Hepworth
> Email address:      michael.w.hepworth@gmail.com
> PostgreSQL version: 8.4
> Operating system:   Ubuntu 10.4
> Description:        sorting issues
> Details:
>
> Have database that is utf-8 encoding so that I can support both english,
> french, and spanish.  Having problems with the ordering of data.
>
> I execute the following sql statment:
>
> select * from (values('HALL, ANDY'),('HALLBERG, FRANK'),('HALLDEN,
> DOUGLAS'),('HALL, DOUGLAS') ) x ORDER BY 1;
>
> and get the following results
>
> HALL, ANDY
> HALLBERG, FRANK
> HALLDEN, DOUGLAS
> HALL, DOUGLAS

What locale did you use? Sort order depends on not only
encoding but also collation.  Please check "SHOW lc_collate".
Your locale seems to just ignore symbol characters.
I have an expected result at least in C locale.

-- 
Itagaki Takahiro



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #6056: sorting issues
  2011-06-13 21:52 BUG #6056: sorting issues Mike Hepworth <michael.w.hepworth@gmail.com>
  2011-06-14 06:44 ` Re: BUG #6056: sorting issues Itagaki Takahiro <itagaki.takahiro@gmail.com>
@ 2011-06-14 13:42   ` Itagaki Takahiro <itagaki.takahiro@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Itagaki Takahiro @ 2011-06-14 13:42 UTC (permalink / raw)
  To: Michael Hepworth <michael.w.hepworth@gmail.com>; +Cc: pgsql-bugs

On Tue, Jun 14, 2011 at 21:28, Michael Hepworth
<michael.w.hepworth@gmail.com> wrote:
> Thanks for the response.  I have created a database with lc_collate =
> en_US.utf8.  This doesn't seem to work.  I does however allow me to sort my
> non english names correctly.  If I drop the database and recreate it with
> lc_collate = C then my english names are ordered correctly but my
> non-english names are sorted incorrectly.

I'm not sure you can use non english names in english locale.
Instead, should you use another locale that covers all characters you use?

I guess locales in libc on Ubuntu 10.4 is just broken or behaves
undesirable as a feature. When I created english locale on Windows,
it returnes expected results in both cases.

Personally, I don't trust locale functions in libc on Linux platforms...

-- 
Itagaki Takahiro



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #6056: sorting issues
  2011-06-13 21:52 BUG #6056: sorting issues Mike Hepworth <michael.w.hepworth@gmail.com>
@ 2011-06-14 11:14 ` hubert depesz lubaczewski <depesz@depesz.com>
  1 sibling, 0 replies; 4+ messages in thread

From: hubert depesz lubaczewski @ 2011-06-14 11:14 UTC (permalink / raw)
  To: Mike Hepworth <michael.w.hepworth@gmail.com>; +Cc: pgsql-bugs

On Mon, Jun 13, 2011 at 09:52:06PM +0000, Mike Hepworth wrote:
> I execute the following sql statment:
> 
> select * from (values('HALL, ANDY'),('HALLBERG, FRANK'),('HALLDEN,
> DOUGLAS'),('HALL, DOUGLAS') ) x ORDER BY 1;
> 
> and get the following results
> 
> HALL, ANDY
> HALLBERG, FRANK
> HALLDEN, DOUGLAS
> HALL, DOUGLAS
> Please Help...

it would help if you would say what do you think is wrong with it.
because, the data is well sorted - prefix hall, and then, the next
sortable character is:
A
B
D
D
in 3rd and 4th string 2nd character is also taken into consideration
because 1st is the same, so it becomes:

A
B
DE
DO

so the sort order is correct.

if you'd expect to get output:
> HALL, ANDY
> HALL, DOUGLAS
> HALLBERG, FRANK
> HALLDEN, DOUGLAS

then the proper solution is to use separate fields for lastname and
firstname, and not put them both in the same column.

In Pg 9.1 you will be able to sort it the way you want using COLLATE
support.

with current situation, you can try to split every string using ", ",
and sort splitted elements separately.

Best regards,

depesz

-- 
The best thing about modern society is how easy it is to avoid contact with it.
                                                             http://depesz.com/



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2011-06-14 13:42 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-13 21:52 BUG #6056: sorting issues Mike Hepworth <michael.w.hepworth@gmail.com>
2011-06-14 06:44 ` Itagaki Takahiro <itagaki.takahiro@gmail.com>
2011-06-14 13:42   ` Itagaki Takahiro <itagaki.takahiro@gmail.com>
2011-06-14 11:14 ` hubert depesz lubaczewski <depesz@depesz.com>

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