Hi Karen,

On 28 Sep., 22:49, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Sep 28, 2009 at 4:00 PM, janedenone <janeden...@googlemail.com>wrote:
>
> > Hi,
>
> > this
>
> > pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<')
>
> > should deliver the same rows as this
>
> > SELECT ... FROM pages WHERE (content NOT REGEXP '^[\n\r \t]*<')
>
> > but it does not: The Django query delivers 468 rows, whereas the SQL
> > query delivers 223. It could be that the Django query does not
> > recognize line endings as mentioned in the character class. Am I
> > missing something?
>
> The Django query is going to be an SQL query also.  To see what Django is
> sending to the DB you should recreate in a shell session and then:
>
> >>> from django.db import connection
> >>> connection.queries[-1]
>
> to see how the query you are expecting compares to the query that is
> actually being issued.  (Note the sql in connection.queries won't have the
> necessary quotes around the regexp parameter -- this quoting is done by the
> backend and therefore not logged in the version stored in
> connection.queries).
>

Thanks a lot! I am aware that Django creates SQL queries for me, but I
did not know how to make them visible. connection.queries shows that
the backslashes preceding my special characters had been escaped:

u'SELECT ... WHERE (NOT (`pages`.`content` REGEXP ^[\\n\\r \\t]*< )
AND NOT (`pages`.`content` REGEXP ^[\\n\\r \\t]*$ )

and I fixed this by changing the Django expression from

pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<').exclude
(content__iregex=r'^[\n\r \t]*$')

to

pages = Page.objects.exclude(content__iregex=u'^[\n\r \t]*<').exclude
(content__iregex=u'^[\n\r \t]*$')

Thanks again,
Jan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to