MySQL limit sub-query problem

293 views
Skip to first unread message

rahul jain

unread,
Jan 26, 2012, 3:10:44 PM1/26/12
to django...@googlegroups.com
All,

I have a query. Its working fine on sqlite server but not working fine
on mysql server.

This is the error message on mysql server: "This version of MySQL
doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery"

This is the query:

inner_q = obj_unassigned.values_list('pk', flat=True)[:diff]
total_objects = (obj_assigned | obj_class.objects.filter(pk__in=inner_q))

Any help appreciated on how to fix this.

Thanks.

RJ

Alasdair Nicol

unread,
Jan 26, 2012, 3:32:21 PM1/26/12
to django...@googlegroups.com
Hi RJ,

On 26/01/12 20:10, rahul jain wrote:
> All,
>
> I have a query. Its working fine on sqlite server but not working fine
> on mysql server.
>
> This is the error message on mysql server: "This version of MySQL

> doesn't yet support 'LIMIT& IN/ALL/ANY/SOME subquery"


>
> This is the query:
>
> inner_q = obj_unassigned.values_list('pk', flat=True)[:diff]
> total_objects = (obj_assigned | obj_class.objects.filter(pk__in=inner_q))
>
> Any help appreciated on how to fix this.
>
> Thanks.
>
> RJ
>

You can prevent the error by using `list()` to fetch the inner queryset
in a separate query:

total_objects = (obj_assigned | obj_class.objects.filter(pk__in=list(inner_q)))

Alasdair

--
Alasdair Nicol
Developer, MEMSET

mail: alas...@memset.com
web: http://www.memset.com/

Memset Ltd., registration number 4504980. 25 Frederick Sanger Road, Guildford, Surrey, GU2 7YD, UK.

rahul jain

unread,
Jan 26, 2012, 5:30:09 PM1/26/12
to django...@googlegroups.com
Works! Great! thanks!!! Lazy querysets!

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

Reply all
Reply to author
Forward
0 new messages