Thread: wrong sort order

wrong sort order

From
"Alejandro D. Burne"
Date:
Hi, maybe there is a problem with sorting latin10? Seems to be like
spaces don't exists just sorting.

Version() ->PostgreSQL 8.0.2 on i686-redhat-linux-gnu,
compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

SELECT nombreasociado, codigoasociado
FROM Asociados
WHERE nombreasociado LIKE 'VILLA%'
ORDER BY 1;

"VILLA CLAUDIA MARIA";2208
"VILLA CLOTILDE";2902
"VILLAFAA'E ALFREDO                 ";916
"VILLAFAA'E MARIA ESTER ROSA        ";933
"VILLAFAA'E MARIA  JULIA            ";7590
"VILLAFANE OSVALDO";3548
"VILLAGGI CARLOS RAUL";1523
"VILLAGRA ILEANA";2305
"VILLAGRA MARIA EUGENIA";7310
"VILLA HORACIO E                    ";2106
"VILLALBA MABEL";397
"VILLALBA ROLANDO A";398
"VILLALBA SILVIA MONICA";2917
"VILLA LUIS SANTIAGO";560
"VILLA MARIA ISABEL";2687
"VILLANI LUCRECIA LILIANA";6657
"VILLANUEVA DIEGO";5888
"VILLANUEVA RICARDO NORBERTO";4608
"VILLA PABLO JOSE";2717
"VILLAR EDUARDO";399
"VILLAR ERNESTO";400
"VILLARES JOSE ANGEL";7174
"VILLAR HUGO EDUARDO";3820
"VILLAR IGNACIO JAVIER";8385
"VILLAR MANUEL ANTONIO";3821
"VILLA ROCA MIGUEL ANGEL";1698
"VILLARREAL NORBERTO";1749
"VILLA SEBASTIAN MARCELO";8159
"VILLA STELLA MARIS";7180
"VILLATA ALBERTO LUIS";7646
"VILLATA MARCELO";5973
"VILLAVICENCIO CARLOS HORACIO";7953

but if you try:

SELECT nombreasociado, codigoasociado
FROM Asociados
WHERE nombreasociado LIKE 'VILLA %'
ORDER BY 1;

"VILLA CLAUDIA MARIA";2208
"VILLA CLOTILDE";2902
"VILLA HORACIO E                    ";2106
"VILLA LUIS SANTIAGO";560
"VILLA MARIA ISABEL";2687
"VILLA PABLO JOSE";2717
"VILLA ROCA MIGUEL ANGEL";1698
"VILLA SEBASTIAN MARCELO";8159
"VILLA STELLA MARIS";7180

 ¿? any clues ¿?

Re: wrong sort order

From
Tom Lane
Date:
"Alejandro D. Burne" <alejandro.dburne@gmail.com> writes:
> Hi, maybe there is a problem with sorting latin10? Seems to be like
> spaces don't exists just sorting.

The guys who write the locale specifications think that's a feature,
not a bug ;-)

If you don't want it, either use C locale or create your own locale
definition.  (I have no idea how easy or hard the latter is.)

            regards, tom lane

Re: wrong sort order

From
"Alejandro D. Burne"
Date:
Maybe I'm wrong, but this "feature" I don't see it in any other rdbms ;-)

2005/7/2, Tom Lane <tgl@sss.pgh.pa.us>:
> "Alejandro D. Burne" <alejandro.dburne@gmail.com> writes:
> > Hi, maybe there is a problem with sorting latin10? Seems to be like
> > spaces don't exists just sorting.
>
> The guys who write the locale specifications think that's a feature,
> not a bug ;-)
>
> If you don't want it, either use C locale or create your own locale
> definition.  (I have no idea how easy or hard the latter is.)
>
>                         regards, tom lane
>

Re: wrong sort order

From
Martijn van Oosterhout
Date:
On Sat, Jul 02, 2005 at 11:28:12AM -0300, Alejandro D. Burne wrote:
> Hi, maybe there is a problem with sorting latin10? Seems to be like
> spaces don't exists just sorting.

It's not the encoding, it's the locale. For example, the en_US sorts in
dictionary order (ignore spaces and case).

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

Re: wrong sort order

From
"Alejandro D. Burne"
Date:
Martjin, this little example show your answer:
$ LANG=es_AR
$ export LANG
$ touch 'villa'
$ touch 'villa f'
$ touch 'villaa'
$ touch 'villat'
$ ls | sort
villa
villaa
villa f
villat

May be this is an off topic, but the question now is how to change or
find a locale that include spaces in sort order.
Thanks!!!, Alejandro.

2005/7/2, Martijn van Oosterhout <kleptog@svana.org>:
> On Sat, Jul 02, 2005 at 11:28:12AM -0300, Alejandro D. Burne wrote:
> > Hi, maybe there is a problem with sorting latin10? Seems to be like
> > spaces don't exists just sorting.
>
> It's not the encoding, it's the locale. For example, the en_US sorts in
> dictionary order (ignore spaces and case).
>
> Hope this helps,
> --

Re: wrong sort order

From
Alvaro Herrera
Date:
On Mon, Jul 04, 2005 at 12:13:27PM -0300, Alejandro D. Burne wrote:

> May be this is an off topic, but the question now is how to change or
> find a locale that include spaces in sort order.

You can hack the locale definitions from the GNU C library.  Start by
getting the source and reading it -- it's far from a trivial task.

Or you can use the C locale.  But you'll find "strange" behavior with ñ
and accented vowels.

--
Alvaro Herrera (<alvherre[a]surnet.cl>)
"Just treat us the way you want to be treated + some extra allowance
 for ignorance."                                    (Michael Brusser)