Hey, On Mon, May 11, 2009 at 9:09 PM, lemming110 <vwfr...@gmail.com> wrote: > > 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? >
Why don't you try using the built-in annotation and aggregation support of django? Should be much easier than trying to do it yourself... http://docs.djangoproject.com/en/dev/topics/db/aggregation/ Matthias --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---