Opened 10 years ago

Closed 10 years ago

#404 closed defect (fixed)

MySQL order_by=['?'] throws ProgrammingError

Reported by: mattycakes@… Owned by: adrian
Component: Metasystem Version:
Severity: normal Keywords: mysql order order_by random
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When attempting to get a list in random order with MySQL as the backend, this error is thrown:

book_list = books.get_list(slug__ne=kwargs['book'], order_by=['?'])
ProgrammingError: (1064, "You have an error in your SQL syntax near '()' at line 1")

I would guess it's a db abstraction issue. MySQL uses ORDER BY RAND() for random ordering, I believe.

Revision 545, MySQL 3.23, Mac OS X.3.9

Change History (4)

comment:1 Changed 10 years ago by mattycakes@…

In django/core/meta/

58:  elif f == '?':
59:      output.append('RANDOM()')

needs to be

58:  elif f == '?':
59:      output.append('RAND()')

for MySQL, but I'm guessing that would then break postgres and/or sqlite. Is there an easy way to abstract it?

comment:2 Changed 10 years ago by adrian

  • Component changed from Database wrapper to Metasystem
  • Status changed from new to assigned

comment:3 Changed 10 years ago by adrian

Added a unit test in [614].

comment:4 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in [615].

Note: See TracTickets for help on using tickets.
Back to Top