Обсуждение: german sort is wrong

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

german sort is wrong

От
Reinhard Asmus
Дата:
Hallo,

i make initdb with --locale='de_DE.utf8'.

the result is:

The database cluster will be initialized with locale de_DE.utf8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "german".

when i make a sort this is the result:

select * from sgvs.test order by bezeichnung;

id | bezeichnung | schlagworte
----+-------------+-------------
  11 | Anton       |
   8 | Ätna        |
  10 | Erna        |
   2 | Kammer      |
   6 | Kanten      |
   1 | Käse        |
   4 | Köbern      |
   3 | Kümmern     |
   5 | Kuno        |
   9 | Möbel       |
   7 | Zuber       |

in german this is wrong. what is the problem?


Re: german sort is wrong

От
"Kevin Grittner"
Дата:
Reinhard Asmus <reinhard.asmus@spdfraktion.de> wrote:

> when i make a sort this is the result:

> [vowel with umlaut sorts equal to vowel without]

> in german this is wrong. what is the problem?

It appears to be one of three different "right" ways:

http://en.wikipedia.org/wiki/German_alphabet#Sorting

Is there a different collation available on your OS to sort names?

-Kevin

Re: german sort is wrong

От
Reinhard Asmus
Дата:
Am 21.03.2012 14:51, schrieb Kevin Grittner:
> Reinhard Asmus<reinhard.asmus@spdfraktion.de>  wrote:
>
>> when i make a sort this is the result:
>
>> [vowel with umlaut sorts equal to vowel without]
>
>> in german this is wrong. what is the problem?
>
> It appears to be one of three different "right" ways:
>
> http://en.wikipedia.org/wiki/German_alphabet#Sorting
>
> Is there a different collation available on your OS to sort names?
>
> -Kevin
>
when i make the same thing in oracle i've got

Ätna
Anton
....

is it possible to get the same with postgresql and when how?

Reinhard


Re: german sort is wrong

От
"Kevin Grittner"
Дата:
Reinhard Asmus <reinhard.asmus@spdfraktion.de> wrote:
> Am 21.03.2012 14:51, schrieb Kevin Grittner:
>> Reinhard Asmus<reinhard.asmus@spdfraktion.de>  wrote:
>>
>>> when i make a sort this is the result:
>>
>>> [vowel with umlaut sorts equal to vowel without]
>>
>>> in german this is wrong. what is the problem?
>>
>> It appears to be one of three different "right" ways:
>>
>> http://en.wikipedia.org/wiki/German_alphabet#Sorting
>>
>> Is there a different collation available on your OS to sort
>> names?

> when i make the same thing in oracle i've got
>
> Ätna
> Anton
> ....
>
> is it possible to get the same with postgresql and when how?

PostgreSQL doesn't implement collations itself; it can only use
collations available from your OS.  It appears that your OS is
defaulting to the dictionary collation and you would prefer the
phone book collation.  The Wikipedia link mentions that Windows
provides both collations; I suspect it's not the only OS that does,
but have no direct knowledge about that.

Starting in version 9.1 PostgreSQL can support collation overrides,
for example at the column level.  Provided that your OS provides
both, you could use one for your default collation and override that
for specific columns, which sounds like it might make sense for
German.

-Kevin

Re: german sort is wrong

От
Reinhard Asmus
Дата:
Am 21.03.2012 14:51, schrieb Kevin Grittner:
> Reinhard Asmus<reinhard.asmus@spdfraktion.de>  wrote:
>
>> when i make a sort this is the result:
>
>> [vowel with umlaut sorts equal to vowel without]
>
>> in german this is wrong. what is the problem?
>
> It appears to be one of three different "right" ways:
>
> http://en.wikipedia.org/wiki/German_alphabet#Sorting
>
> Is there a different collation available on your OS to sort names?
>
> -Kevin
>
when i make the same thing in oracle i've got

Ätna
Anton
....

is it possible to get the same with postgresql and when how?

Reinhard


Re: german sort is wrong

От
BGoebel
Дата:
Reinhard Asmus wrote
>
> when i make the same thing in oracle i've got
>
> Ätna
> Anton
> ....
>
> is it possible to get the same with postgresql and when how?
>
>

PostgreSQLs collation support is not complete. Until now, you can not define
a sort order of your own.

Workaround:

Step1: Define a function like this

  CREATE OR REPLACE FUNCTION germanorder(text)
    RETURNS text AS
  $BODY$ SELECT
REPLACE(REPLACE(REPLACE(REPLACE(lower($1),'ß','ss'),'ä','ae'),'ö','oe'),'ü','ue')
$BODY$
    LANGUAGE sql VOLATILE
    COST 100;
  ALTER FUNCTION prisorder(text)
    OWNER TO postgres;

step2:  Create an functional index
 ( http://www.postgresql.org/docs/7.3/static/indexes-functional.html )
CREATE INDEX bezeichnung_germanorder_idx ON test1 (germanorder(col1));

step3: Select using the function
select * from sgvs.test order by germanorder(bezeichnung);

and you will get what you want...

If speed does not matter you can omit step2.

regards



--
View this message in context: http://postgresql.1045698.n5.nabble.com/german-sort-is-wrong-tp5582836p5590321.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.