Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#11332 closed (invalid)

Group by doesn't work properly with PosgreSQL

Reported by: Loststylus Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am trying to execute a query running Django 1.0.2 with PostgreSQL 8.3:

from accounts import models as m
from django.contrib.auth.models import User
me = User.objects.get(pk=1)
me

<User: root>

messages_from_me = m.PersonalMessage.objects.filter(from_id = me, hide_from = False).order_by('-time','-pk')
messages_from_me.query.group_by=-to_id_id

I get the following error:

Traceback (most recent call last):

File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 147, in repr

data = list(self[:REPR_OUTPUT_SIZE + 1])

File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 162, in len

self._result_cache.extend(list(self._iter))

File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 275, in iterator

for row in self.query.results_iter():

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 206, in results_iter

for rows in self.execute_sql(MULTI):

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 1734, in execute_sql

cursor.execute(sql, params)

File "/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py", line 19, in execute

return self.cursor.execute(sql, params)

ProgrammingError: колонка "accounts_personalmessage.id" должна фигурировать в выражении GROUP BY или использоваться в агрегатной функции

The last line is in Russian, it says something like column "accounts_personalmessage.id" should be in GROUP BY expression or should be used in aggregation function.

The same code works normally for sqlite.

Change History (7)

comment:1 by Loststylus, 16 years ago

Summary: Group by doesn't work properly with PostgreSQLGroup by doesn't work properly with PosgreSQL

comment:2 by Loststylus, 16 years ago

Sorry, missed the <code> tag. Here it goes with the normal formatting:

>>>from accounts import models as m 
>>>from django.contrib.auth.models import User me = User.objects.get(pk=1) me
<User: root>
>>>messages_from_me = m.PersonalMessage.objects.filter(from_id = me, hide_from = False).order_by('-time','-pk')
>>>messages_from_me.query.group_by=['-to_id_id']

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 147, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 162, in __len__
    self._result_cache.extend(list(self._iter))
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 275, in iterator
    for row in self.query.results_iter():
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 206, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 1734, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
ProgrammingError: колонка "accounts_personalmessage.id" должна фигурировать в выражении GROUP BY или использоваться в агрегатной функции

I get the following error:

comment:3 by Russell Keith-Magee, 16 years ago

Resolution: invalid
Status: newclosed

query.group_by is an undocumented, unsupported internal attribute. It is not intended for use by end users. If you use it, you do so at your own peril.

Formal support for aggregation functions isn't available in Django v1.0. Aggregation has been added in trunk, and will be available in Django v1.1. See the documentation for more details.

comment:4 by Loststylus, 16 years ago

Hmm, i know that it's not documented and that there'll be aggregation in the upcoming version of Django. But, unfortunately, i need it now with stable Django version. Is there any way i can fix the problem myself?

comment:5 by Loststylus, 16 years ago

Resolution: invalid
Status: closedreopened

comment:6 by Russell Keith-Magee, 16 years ago

Resolution: invalid
Status: reopenedclosed

Please don't re-open a ticket that has been closed. This ticket was closed because what was reported wasn't a bug. If you have a "how do I do this" question, it should be asked on the mailing list, not in the ticket tracker.

comment:7 by Loststylus, 16 years ago

My apologies.

Note: See TracTickets for help on using tickets.
Back to Top