Opened 19 years ago

Closed 19 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

Description

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 by mattycakes@…, 19 years ago

In django/core/meta/init.py:

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

Component: Database wrapperMetasystem
Status: newassigned

comment:3 by Adrian Holovaty, 19 years ago

Added a unit test in [614].

comment:4 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: assignedclosed

Fixed in [615].

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