Was working on
MDL-21437, when I detected that some fields that internally are using $DB->sql_cast_char2real(), weren't being properly casted, causing wrong sorts.
Looking at drivers implementation, only moodle_database has one default implementation and moodle_pgsql_database a custom one.
Also, tests were incomplete/inaccurate enough to cause us to think that everything was under control. So I'm going to implement the sql_cast_char2real() method for the drivers missing it and create/modify tests, to check for those implementations better.