title: PostgreSQL 9.1 using collate in select statements
body: <p>I have a postgresql 9.1 database table, "en_US.UTF-8":</p>
  
  <pre><code>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,
      ....
  )
  </code></pre>
  
  <p>The attribute name_language contains names in various languages. The language is specified by the foreign key language_id.</p>
  
  <p>I have created a few indexes:</p>
  
  <pre><code>/* us english */
  CREATE INDEX idx_branch_language_2
      ON branch_language
      USING btree
      (name_language COLLATE pg_catalog."en_US" );
  
  /* catalan */
  CREATE INDEX idx_branch_language_5
      ON branch_language
      USING btree
      (name_language COLLATE pg_catalog."ca_ES" );
  
  /* portuguese */
  CREATE INDEX idx_branch_language_6
      ON branch_language
      USING btree
      (name_language COLLATE pg_catalog."pt_PT" );
  </code></pre>
  
  <p>Now when I do a select I am not getting the results I am expecting. </p>
  
  <pre><code>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
  </code></pre>
  
  <p>This generates a list of names but not in the order I expected:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>As I expected the last two entries to appear in different positions in the list.</p>
  
  <p>Creating the indexes works. I don't think they are really necessary unless you want to optimize for performance.</p>
  
  <p>The select statement however seems to ignore the part: collate "ca_ES".</p>
  
  <p>This problem also exists when I select other collations. I have tried "es_ES" and "pt_PT" but the results are similar.</p>