Yes that was the problem, thanks! On Mon, Nov 30, 2009 at 18:21, Craig Kimerer <craig.kime...@gmail.com>wrote:
> No guarantees that this will fix the issue, but have you tried escaping the > '%'? > > Try `Semestre.objects.extra(where=['num %% 2 = 0'])` and this may give you > your desired result. Looks like an issue with python string formatting. > > Alternatively, you could try `print Semestre.objects.extra(where=['num %% 2 > = 0']).query` to see what it's trying to execute on the database itself, > which may help you track down your problem. > > Craig > > On Mon, Nov 30, 2009 at 8:50 AM, Marcos Marín <marcosma...@gmail.com>wrote: > >> Hi, I'm trying to do a query where I select all rows where a field is >> divisible by 2. In pure SQL this is what I want: >> select * from contenido_semestre where num % 2 = 0; >> which works fine. When trying to do it with Django I do >> Semestre.objects.extra(where=['num % 2 = 0']) >> But this gets me an empty list as a result (I'm using the exact same >> database for testing). >> >> The problem seems to be only with the modulo operation, using 'num + 2 = >> 4' for example works correctly. >> >> Is this a bug or by design. And what would you suggest as a workaround? >> I'd rather not do custom SQL but will if it is the only other option. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.