Opened 13 years ago

Closed 13 years ago

#404 closed defect (fixed)

MySQL order_by=['?'] throws ProgrammingError

Reported by: mattycakes@… Owned by: Adrian Holovaty
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: no UI/UX: no


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 13 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 13 years ago by Adrian Holovaty

Component: Database wrapperMetasystem
Status: newassigned

comment:3 Changed 13 years ago by Adrian Holovaty

Added a unit test in [614].

comment:4 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: assignedclosed

Fixed in [615].

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