Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 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: UI/UX:

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.

Attachments (0)

Change History (7)

comment:1 Changed 5 years ago by Loststylus

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Group by doesn't work properly with PostgreSQL to Group by doesn't work properly with PosgreSQL

comment:2 Changed 5 years ago by Loststylus

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 Changed 5 years ago by russellm

  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 5 years ago by Loststylus

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 Changed 5 years ago by Loststylus

  • Resolution invalid deleted
  • Status changed from closed to reopened

comment:6 Changed 5 years ago by russellm

  • Resolution set to invalid
  • Status changed from reopened to closed

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 Changed 5 years ago by Loststylus

My apologies.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.