Discussion:
[ADMIN] german sort is wrong
(too old to reply)
Reinhard Asmus
2012-03-20 15:13:24 UTC
Permalink
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?
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Kevin Grittner
2012-03-21 13:51:06 UTC
Permalink
[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
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Reinhard Asmus
2012-03-22 10:24:30 UTC
Permalink
Post by Kevin Grittner
[vowel with umlaut sorts equal to vowel without]
in german this is wrong. what is the problem?
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
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Kevin Grittner
2012-03-22 15:39:53 UTC
Permalink
Post by Reinhard Asmus
Post by Kevin Grittner
[vowel with umlaut sorts equal to vowel without]
in german this is wrong. what is the problem?
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
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Reinhard Asmus
2012-03-21 14:21:54 UTC
Permalink
Post by Kevin Grittner
[vowel with umlaut sorts equal to vowel without]
in german this is wrong. what is the problem?
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
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
BGoebel
2012-03-23 18:04:57 UTC
Permalink
Post by Reinhard Asmus
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.
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Loading...