title: Postgres ordering of UTF-8 characters
body: <p>I'm building a small app that includes Esperanto words in my database, so I have words like ĉapelojn and brakhorloĝo, with "special" characters.</p>
  
  <p>Using PostgreSQL 9.4.4 I have a <code>words</code> table with the following schema:</p>
  
  <pre><code>lingvoj_dev=# \d words
                                        Table "public.words"
     Column    |            Type             |                     Modifiers
  -------------+-----------------------------+----------------------------------------------------
   id          | integer                     | not null default nextval('words_id_seq'::regclass)
   translated  | character varying(255)      |
   meaning     | character varying(255)      |
   times_seen  | integer                     |
   inserted_at | timestamp without time zone | not null
   updated_at  | timestamp without time zone | not null
  Indexes:
      "words_pkey" PRIMARY KEY, btree (id)
  </code></pre>
  
  <p>But the following query gives some strange output:</p>
  
  <pre><code>lingvoj_dev=# SELECT w."translated" FROM "words" AS w ORDER BY w."translated" desc limit 10; 
  translated
  ------------
   ĉu
   ŝi
   ĝi
   ĉevaloj
   ĉapelojn
   ĉapeloj
   ĉambro
   vostojn
   volas
   viro
  (10 rows)
  </code></pre>
  
  <p>The ordering is inconsistent - I'd be okay with all of the words starting with special characters being at the end, but all of the words starting with ĉ should be grouped together and they're not! Why do ŝi and ĝi come in between ĉu and ĉevaloj?</p>
  
  <p>The server encoding is UTF8, and the collation is en_AU.UTF-8.</p>
  
  <p><em>edit:</em> It looks like it's sorting all of the special characters as equivalent - it's ordering correctly based on the second character in each word. How do I make PostgreSQL see that ĉ, ŝ and ĝ are not equivalent?</p>