Thread: RES: RES: Issue on Varchar Ordering

RES: RES: Issue on Varchar Ordering

From
Erika Terahata Torres Prada e Silva - MPS
Date:
Thanks everybody.


The correct order in Portuguese would return as brazilian telephone guide
order as below:

select * from aluno order by nome
    id    nome
    38    GABRIEL ALCIDES KLIM PERONDI
    40    GABRIEL ALEXANDRE DA SILVA MANICA
    36    GABRIELA HELEDA DE SOUZA
    37    GABRIELA JACOBY NOS
    39    GABRIELA LETICIA BATISTA NUNES

Indeed using POSIX, C, the result above is Ok, but it doesn't work for me
because of the accented and special characters.

-----Mensagem original-----
De: Alvaro Herrera [mailto:alvherre@commandprompt.com]
Enviada em: quinta-feira, 17 de agosto de 2006 11:53
Para: Erika Terahata Torres Prada e Silva - MPS
Cc: pgsql-admin@postgresql.org
Assunto: Re: RES: [ADMIN] Issue on Varchar Ordering

Erika Terahata Torres Prada e Silva - MPS wrote:
> Peter,
>
> Thanks for answering.
>
> But it's not correct to my language pt_BR and it worked correctly with
> PostgreSQL at Windows and FreeBSD. I have this problem only with Debian
and
> now I'm looking for some Debian related issue.

It's still correct -- it's the ordering you'll find on the telephone
guide.  It works the same for portuguese and for spanish and a lot
others.  The problem with going to C locale (POSIX), as suggested in a
related follow-up, is that it sorts by byte value, which is not at all
correct when you start sorting stuff that contains funny letters
(accented vowels, etc).  It works for english people just because they
don't worry about accents at all.  I wonder if portuguese has special
sorting rules for "nh", for example?  You'll lose that if you just
change to the C locale.

I think you _can_ define a collation on which spaces are significant,
but it's also a significant amount of work.  (And IMHO not at all worth
the trouble.)

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Re: RES: RES: Issue on Varchar Ordering

From
Alvaro Herrera
Date:
Erika Terahata Torres Prada e Silva - MPS wrote:
>
> Thanks everybody.
>
>
> The correct order in Portuguese would return as brazilian telephone guide
> order as below:
>
> select * from aluno order by nome
>     id    nome
>     38    GABRIEL ALCIDES KLIM PERONDI
>     40    GABRIEL ALEXANDRE DA SILVA MANICA
>     36    GABRIELA HELEDA DE SOUZA
>     37    GABRIELA JACOBY NOS
>     39    GABRIELA LETICIA BATISTA NUNES
>
> Indeed using POSIX, C, the result above is Ok, but it doesn't work for me
> because of the accented and special characters.

I stand corrected -- that is the sort order returned by sort under the
pt_BR locale (which is indeed different from the spanish sort order).

What's your lc_collate setting?  What does this return on your system?

LC_COLLATE=pt_PT sort << EOF
GABRIEL ALEXANDRE DA SILVA MANICA
GABRIELA JACOBY NOS
GABRIELA HELEDA DE SOUZA
GABRIELA LETICIA BATISTA NUNES
GABRIEL ALCIDES KLIM PERONDI
EOF

On my system it outputs the order you show above, which shows that my
locale is correctly defined per your expectations.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Re: RES: RES: Issue on Varchar Ordering

From
Peter Eisentraut
Date:
Alvaro Herrera wrote:
> LC_COLLATE=pt_PT sort << EOF
> GABRIEL ALEXANDRE DA SILVA MANICA
> GABRIELA JACOBY NOS
> GABRIELA HELEDA DE SOUZA
> GABRIELA LETICIA BATISTA NUNES
> GABRIEL ALCIDES KLIM PERONDI
> EOF
>
> On my system it outputs the order you show above, which shows that my
> locale is correctly defined per your expectations.

That is absolutely wild.  This will indeed return a space-sensitive sort
under pt_BR, but not under, say, de_DE.  So there is order in this
world! (heh)

This is on Debian, so the original poster has some configuration or
version difference.  Please tell OS version, and the output of "SHOW
lc_collate".

--
Peter Eisentraut
http://developer.postgresql.org/~petere/