Обсуждение: BUG #4338: Order by seems to trim some characters before sort

Поиск
Список
Период
Сортировка

BUG #4338: Order by seems to trim some characters before sort

От
"Domingo Alvarez Duarte"
Дата:
The following bug has been logged online:

Bug reference:      4338
Logged by:          Domingo Alvarez Duarte
Email address:      mingodad@gmail.com
PostgreSQL version: 8.2.9
Operating system:   linux
Description:        Order by seems to trim some characters before sort
Details:

I have a test table:
CREATE TABLE test
(
  id serial NOT NULL,
  t character varying,
  CONSTRAINT test_pkey PRIMARY KEY (id)
)
with tis data retrieved by: select * from test order by 2

4;"---abacate"
3;"arpa"
5;"--- bacate"
1;"dad"
2;"--dad"

I expect the result to be :

5;"--- bacate"
4;"---abacate"
2;"--dad"
3;"arpa"
1;"dad"

It seems that postgresql is issuing a kind of trim on the column value
before sort/compare, because it's ignoring spaces and '-' wich I use
propositally to move some values to front.

Why postgresql is behaving this way ?
I couldn't find an expalanation in the documentation.

Re: BUG #4338: Order by seems to trim some characters before sort

От
Tom Lane
Дата:
"Domingo Alvarez Duarte" <mingodad@gmail.com> writes:
> It seems that postgresql is issuing a kind of trim on the column value
> before sort/compare, because it's ignoring spaces and '-' wich I use
> propositally to move some values to front.

> Why postgresql is behaving this way ?

Because the LC_COLLATE setting is telling it to.  If you try sorting
the same data with sort(1) I'll bet you get the same result.  This
is standard behavior for quite a lot of locale settings.

If you don't like the result then you need to switch to a different
locale setting, probably "C".  Unfortunately, that requires dump,
re-initdb with the correct locale option, reload :-(

            regards, tom lane