I have a postgresql 9.1 database table, "en_US.UTF-8":
CREATE TABLE branch_language ( id serial NOT NULL, name_language character varying(128) NOT NULL, branch_id integer NOT NULL, language_id integer NOT NULL, .... )
The name_language attribute contains names in different languages. The language is specified by the foreign key language_id.
I created several indexes:
CREATE INDEX idx_branch_language_2 ON branch_language USING btree (name_language COLLATE pg_catalog."en_US" ); CREATE INDEX idx_branch_language_5 ON branch_language USING btree (name_language COLLATE pg_catalog."ca_ES" ); CREATE INDEX idx_branch_language_6 ON branch_language USING btree (name_language COLLATE pg_catalog."pt_PT" );
Now, when I make a choice, I do not get the expected results.
select name_language from branch_language where language_id=42 -- id of catalan language order by name_language collate "ca_ES" -- use ca_ES collation
This generates a list of names, but not in the expected order:
Aficions i Joguines Agència de viatges Aliments i Subministraments Aparells elèctrics i il luminació Art i Antiguitats Articles de la llar Bars i Restaurants ... Tabac Àudio, Vídeo, CD i DVD Òptica
As I expected, the last two entries will appear in different positions on the list.
Creating indexes works. I do not think that they are really necessary if you do not want to optimize performance.
The select statement, however, ignores the: collate "ca_ES" part.
This problem also occurs when I select other sorts. I tried "es_ES" and "pt_PT", but the results are similar.