@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

postgresのDockerコンテナでソート順をバイトオーダーにする

postgresでvarcharのソート順が文字列ソートじゃなくて数値ソートみたいになっていた。
collate "C" をorder句に追加すればバイトオーダーでソートしてくれ、意図した順にソートされた。

postgres=# select name from test order by name;
 name
------
 あ
 い
 ああ
 いい
(4 rows)

postgres=#  select name from test order by name collate "C";
 name
------
 あ
 ああ
 い
 いい
(4 rows)

遭遇したエラー、参考URLなど

postgres=#  select name from test order by name collate "ja_JP";
ERROR:  collation "ja_JP" for encoding "UTF8" does not exist
postgres=# create collation "ja_JP.utf8" (LOCALE = 'ja_JP.UTF-8');
ERROR:  could not create locale "ja_JP.UTF-8": Success