Quoting in extra(select=...) expression

7 views
Skip to first unread message

lemming110

unread,
May 11, 2009, 2:33:25 PM5/11/09
to Django developers
I am trying to use the select keyword in extra. But I cannot properly
quote the the expression for postrgres. I am using the
django.contrib.comments. I started with this snippet
http://www.djangosnippets.org/snippets/1101/ which returns the number
of comments for an object. However, the code does not work. The
problem that the field django_comment.object_pk is text and my item pk
is integer.

In postgres, this works:

select count(*)
from django_comments
where django_comments.content_type_id=12 and
django_comments.object_pk='332';

But using extra(select={'comment_count': sql,}) where

sql = '''select count(*)
from django_comments
where django_comments.content_type_id=12 and django_comments.object_pk=
%s'''

gives me an error every way that I have tried to add quotes. (This
includes django.db.connection.ops.quote_name.)

Any ideas on how to embedded quotes in postgres?

Ian Kelly

unread,
May 11, 2009, 2:54:23 PM5/11/09
to django-d...@googlegroups.com

Please ask questions about how to use Django on the django-users
mailing list. This list is for discussion about the development of
Django itself.

Thanks,
Ian

Reply all
Reply to author
Forward
0 new messages