Opened 16 years ago
Last modified 13 years ago
#7580 closed
Support ORDER BY BINARY in MySQL — at Initial Version
Reported by: | Owned by: | Paul Kenjora | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | mysql, binary, order by |
Cc: | mmitar@… | Triage Stage: | Design decision needed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The Problem:
MySQL supports both ORDER BY and ORDER BY BINARY.
ORDER BY does NOT match the string sort used by Python but ORDER BY BINARY DOES. Lots of issues arise when returned list from DB needs to be in proper order.
The problem is described well at: http://blog.awarelabs.com/?p=18
The Proposed Fix:
Add a 'binary' tag to the end of any order_by('column') caluse, like so order_by('columnbinary').
Strip the 'binary' tag before any processing and ensure 'BINARY ' is inserted into generated SQL.
The above solution ensures existing behavior is not altered. It does carry the side effect of making 'binary' a reserved word which come to think of it is reserved in SQL so no issue there.