Modify

Opened 18 years ago

Closed 18 years ago

#1435 closed defect (fixed)

Invalid aggregate query

Reported by: x@… Owned by: Radek Bartoň
Priority: normal Component: DiscussionPlugin
Severity: normal Keywords: sql
Cc: Trac Release: 0.10

Description (last modified by Noah Kantrowitz)

Saw this in my logs:

Apr  6 16:29:53 ops5 postgres[17289]: [2-1] ERROR:  column "topic.subject" must appear in the GROUP BY clause or be used in an aggregate function
Apr  6 16:29:53 ops5 postgres[17289]: [2-2] STATEMENT:  SELECT m.id, m.forum, m.topic, m.time, m.author, m.body, t.subject FROM message m LEFT JOIN (SELECT subject, id FROM
Apr  6 16:29:53 ops5 postgres[17289]: [2-3]  topic GROUP BY id) t ON t.id = m.topic WHERE body LIKE '%subversion%'

Appears to be coming from:

sql = "SELECT m.id, m.forum, m.topic, m.time, m.author, m.body," \
" t.subject FROM message m LEFT JOIN (SELECT subject, id FROM" \
" topic GROUP BY id) t ON t.id = m.topic WHERE body LIKE '%%%s%%'" \
 % (query)

That subquery is not valid usage of a group by; ie, which subject should it be yielding for each id? Using min() or max() might be a reasonable stop gap. However, AFA Postgres is concerned, I think DISTINCT ON () would be the usual way to go. Of course, I'm not sure of DISTINCT ON's portability(dont use mysql or sqlite).

Attachments (0)

Change History (2)

comment:1 Changed 18 years ago by Noah Kantrowitz

Description: modified (diff)

Fixing formatting

comment:2 Changed 18 years ago by Radek Bartoň

Resolution: fixed
Status: newclosed

I'm not sure why there was GROUP BY anyway, maybe piece of some orphaned code. Should be fixed with changeset 2166.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Radek Bartoň.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.