Search code examples
mysqlscalaslickplay-slick

In Scala, when making a slick sortBy, how can I have it do a case-sensitive sort


I found the Scala slick package's "sortBy" method is not case sensitive. Ex: after implementing the following command: q.sortBy(columnMap("name").desc), I got:

TestingIsFun, testing foo1, Testing foo,

Is this expected behavior? How can I make it case sensitive? Thx.


Solution

  • I think as it currently stands, slick just depends on the RDBMS default handling of case in sorting. You did not mention the RDBMS type, but e.g. in mysql, case-insensitive is the default in sorting. However, you can define a column to-be-sorted in a way overiding that, in mysql, as per Altering Mysql Table column to be case sensitive. This will work without having to touch the query or slick parameters, as the solution is at the schema definition level. It should be possible to define the column as a binary string in the first place, with slick if needed:

    O.DBType("binary") in the slick column definition should work for that.