Since this is an eccentricity of PostgreSQL, it would be a good idea for us to modify that example in the docs, and use a more conventional GROUP BY statement that would be familiar to all SQL dialects. I've opened ticket #20168 to track this issue.
Yours,
Russ Magee %-)
On Sun, Mar 31, 2013 at 5:49 AM, James Durham <jamesldurham@gmail.com> wrote:
In this instance, what I'm asking is about the documentation.
In other words does anyone recognize the dialect.
It would just help in understanding docs.
Though, thanks for indicating that it is backend dependent.
On Friday, March 29, 2013 8:40:09 PM UTC-5, Russell Keith-Magee wrote:On Sat, Mar 30, 2013 at 6:20 AM, James Durham <jamesl...@gmail.com> wrote:In the example:class PollManager(models.Manager): def with_counts(self): from django.db import connection cursor = connection.cursor() cursor.execute(""" SELECT p.id, p.question, p.poll_date, COUNT(*) FROM polls_opinionpoll p, polls_response r WHERE p.id = r.poll_id GROUP BY 1, 2, 3 ORDER BY 3 DESC""") result_list = [] for row in cursor.fetchall(): p = self.model(id=row[0], question=row[1], poll_date=row[2]) p.num_responses = row[3] result_list.append(p) return result_list class OpinionPoll(models.Model): question = models.CharField(max_length=200) poll_date = models.DateField() objects = PollManager() class Response(models.Model): poll = models.ForeignKey(OpinionPoll) person_name = models.CharField(max_length=50) response = models.TextField()
What is the sql dialect that is used.In this case you're opening a cursor, so you use whatever dialect your database uses. If you're using PostgreSQL, use PostgreSQL syntax; if you're using MySQL, use MySQL syntax.
Django's ORM hides syntax differences from you; but once you start dealing with database cursors or raw() queries, you're coding right to the metal, so your deployment environment matters.
Yours,Russ Magee %-)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment