The following query in line 1548 of comment.module is causing problem in PostgreSQL 7.5.4. PostgreSQL complains that v.weight is not part of the GROUP BY clause.
$result = db_query('SELECT v.mid, v.vote, MAX(r.value) AS value FROM {moderation_votes} v INNER JOIN {moderation_roles} r ON r.mid = v.mid WHERE r.rid IN (%s) GROUP BY v.mid, v.vote ORDER BY weight', implode(', ', array_keys($user->roles)));
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | drupal-4-6-comment-12071.diff | 1.56 KB | Cvbge |
| #4 | comment.module_1.patch | 2.07 KB | mousse-man |
Comments
Comment #1
mousse-man commentedThe bug is also very visible in the workspace module. However, I have no clue where the workspace module is accessing functionality of the comments module.
If I feed it the query
SELECT v.mid, v.vote, MAX(r.value) AS value FROM moderation_votes v INNER JOIN moderation_roles r ON r.mid = v.mid WHERE r.rid IN (3) GROUP BY v.mid, v.vote, v.weight ORDER by v.weight DESC;
it works, and actually the 'only' trick to this is to add 'v.weight' in the GROUP BY clause.
This error message gets printed when I activate the workspace module and then click 'my workspace':
warning: pg_query(): Query failed: ERROR: column "v.weight" must appear in the GROUP BY clause or be used in an aggregate function
. in /var/www/html/includes/database.pgsql.inc on line 104.
user error:
query: SELECT v.mid, v.vote, MAX(r.value) AS value FROM moderation_votes v INNER JOIN moderation_roles r ON r.mid = v.mid WHERE r.rid IN (3) GROUP BY v.mid, v.vote ORDER BY weight in /var/www/html/includes/database.pgsql.inc on line 121.
This means that if we change the line 1548 to the following:
$result = db_query('SELECT v.mid, v.vote, MAX(r.value) AS value FROM {moderation_votes} v INNER JOIN {moderation_roles} r ON r.mid = v.mid WHERE r.rid IN (%s) GROUP BY v.mid, v.vote, v.weight ORDER BY weight', implode(', ', array_keys($user->roles)));
it doesn't display any error message anymore. Is this the solution?
Comment #2
(not verified) commentedI hade the same problem on my site today. I added "weight" column to the group by clause to fix the error.
The original query in comment.module is not correct in Postgress. You can not run it manually, as you will get the error message. I hope the fix will go quickly to the drupal core.
Comment #3
ttt commentedIn addition, the query on line 776 does not work in PostgreSQL either.
Adding c.format as part of the GROUP BY clause solves the problem.
Comment #4
mousse-man commentedSo this would give the following patch, as attached below, against the 4.5.1 comment module.
Comment #5
killes@www.drop.org commentedDoesn't apply anymore.
Comment #6
Cvbge commentedThe first bug seems to be fixed. The SQL is a bit different, the weight is MAXed and works with postgres:
I don't know how to trigger the second bug (from #3), but I agree that the sql is not correct and proposed fix is ok.
Attached patch fixes the second bug, it's for 4.6.
Thanks you for your reports.
Comment #7
dries commentedCommitted to HEAD. Thanks.
Comment #8
(not verified) commented