In postgreSQL all selected columns (which are not aggregated) must appear in GROUP BY clause.
In error log:
query: SELECT t.tag, t.tag_id, t.public, COUNT(ti.thread_id) as count FROM prod_pm_tags t LEFT JOIN prod_pm_tags_index ti ON t.tag_id = ti.tag_id WHERE (ti.uid = 90) GROUP BY t.tag_id, t.tag ORDER BY t.tag ASC in modules/privatemsg/privatemsg_filter/privatemsg_filter.module on line 297.
In psql command line:
# SELECT t.tag, t.tag_id, t.public, COUNT(ti.thread_id) as count FROM prod_pm_tags t LEFT JOIN prod_pm_tags_index ti ON t.tag_id = ti.tag_id WHERE (ti.uid = 90) GROUP BY t.tag_id, t.tag ORDER BY t.tag ASC ;
ERROR: column "t.public" must appear in the GROUP BY clause or be used in an aggregate function
The correct query would be:
# SELECT t.tag, t.tag_id, t.public, COUNT(ti.thread_id) as count FROM prod_pm_tags t LEFT JOIN prod_pm_tags_index ti ON t.tag_id = ti.tag_id WHERE (ti.uid = 90) GROUP BY t.tag_id, t.tag, t.public ORDER BY t.tag ASC ;
Please fix.
Thank you,
Gabor
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | privatemsg.pgsql_groupby_fix.patch | 1006 bytes | berdir |
Comments
Comment #1
berdirThanks. I'll try to remember to our test suite (which would have found that bug) more often on PostgreSQL :)
Attached is a patch that should fix this, please test and set to RTBC.
Comment #2
berdirThanks, fixed in 6.x-1.x-dev and 7.x-1.x-dev.
Comment #3
gatoth commentedThanx. Works for me too, like a charm. But I have no clue where to set RTBC.
Comment #4
berdirI've already commited it, so you don't need to to that anymore.
For the next time, RTBC is short for "reviewed & tested by the community" which is status you can set. It means that you tested a patch and can verify that it does work as expected.
You can find more information about that here: http://drupal.org/node/156119