I have a Rails 4.2+ and Postgres 9.4 project and I need to change how Postgres orders items in a query. The default settings seem to ignore whitespace and I need a strategy that takes white space into account. After running \l in psql, I see the db has Collate set to en_US.UTF-8 and Ctype set to en_US.UTF-8.
Updated 12/30/15 4:14pm
I have the following Activities with a name column with the following names:
Code1A East
Code1A West
Code1 AEast
Code1 AWest
When I execute the following query in Rails
Activity.order(name: :asc)
I expected to get back a list of Activities in the following order.
Code1 AEast
Code1 AWest
Code1A East
Code1A West
or maybe even
Code1A East
Code1A West
Code1 AEast
Code1 AWest
Instead I get
Code1A East
Code1 AEast
Code1A West
Code1 AWest
It appears to be disregarding the space in the name. I noted in a comment below, I was able to get the Rails app to create a DB with a specific collation by adding the following to database.yml
development:
...other keys...
encoding: utf8
collation: sv_SE.UTF-8
ctype: sv_SE.UTF-8
template: template0
But I don't know which collation setting will pick a "better" sort order.