extra tables subselect issue in QS refactor?

13 views
Skip to first unread message

offspinner

unread,
May 1, 2008, 2:44:14 AM5/1/08
to Django users
Hi folks,

I have several rather large SQL queries that I want to return a QS. I
need to put a subselect in the tables part of "extra" to achieve this.
The example below I can refactor to be more conventional but I have
other examples where I need to use this construct.

It *seems* since QS refactor's trunk merge (r.7483 on MySQL 5.0.41)
that *my* code is broken, throwing a MySQL error. It did work before.

ProgrammingError at /
(1103, "Incorrect table name '(SELECT DISTINCT f.id\n\t\tFROM
films_film AS f\n\t\tJOIN films_listing AS l ON l.film_id = f.id\n\t
\tWHERE l'")

Below is the custom manager:

class FilmsManager(models.Manager):
"""custom methods for film data"""
def new_films(self):
"""return 10 new films"""
return self.extra(
tables=["""(SELECT DISTINCT f.id
FROM films_film AS f
JOIN films_listing AS l ON l.film_id = f.id
WHERE l.starttime > NOW( )
AND f.year !=0000
ORDER BY year DESC
LIMIT 0 , 10) as topten"""],
where=['films_film.id = topten.id']
)

Has anything changed in the way these queries are assembled in pure
SQL? How would you go about debugging this?

Best wishes and thanks!



offspinner

unread,
May 1, 2008, 5:24:17 AM5/1/08
to Django users
This issue seems to be similar/same as the another post made today

http://groups.google.com/group/django-users/browse_thread/thread/ef17cb9fff6d0391
Reply all
Reply to author
Forward
0 new messages