Postgresql – Sort name by Thai character is not working

collationpostgresqlpostgresql-9.1

I am trying to sort a table by name. The name are in Thai character;

>Select name from product_categ
                    name                    
--------------------------------------------
 ระงับกลิ่นกาย
 สกินแคร์ (ดูแลผิวหน้า)
 รองเท้า
 ผู้หญิง
 เมคอัพ
 น้ำหอม
 วิตามิน อาหารเสริม
 เส้นบุก, บุกก้อน

When I try to sort the table by name, it does not work.(it does sort but is sorting in some different way / probably using the equivalent of Thai Character ?)

>Select name from product_categ order by name;
                    name                    
--------------------------------------------
 ชา กาแฟ เครื่องดื่มชงสำเร็จ
 ร่ม กันฝน พวงกุญแจ
 หมวก
 หมวก
 เล็บ
 แป้ง

So i tried to google and find a solution where i came across using collation directly in the query.However the query is not working for me.

select name from product_categ order by name COLLATE 'th_TH';

I receive and error mentioning error at 'th_th';

Any suggestion to fix this will be a much appreciated.

Best Answer

You need to specify that it's a UTF-8 collation:

SELECT name
FROM product_categ
ORDER BY name COLLATE "th_TH.UTF-8";