When attempting to use the troll module with Postgres, I receive the following error when attempting to view the troll admin page:
* warning: pg_query() [function.pg-query]: Query failed: ERROR: column "u.name" must appear in the GROUP BY clause or be used in an aggregate function in /opt/www/drupal-4.7.int.thatsbj.com/includes/database.pgsql.inc on line 84.
* user warning: query: SELECT u.uid, u.name, u.mail, u.status, t.ip_address, MAX(t.accessed) AS recorded, u.created FROM users u LEFT JOIN troll_ip_track t ON u.uid = t.uid WHERE u.uid != 0 GROUP BY u.uid ORDER BY u.name ASC LIMIT 25 OFFSET 0 in /opt/www/drupal-4.7.int.thatsbj.com/includes/database.pgsql.inc on line 103.
In Postgres, the GROUP BY clause must include the columns referred to in the SELECT or it will result in an error. I have modified the line:
$sql .= ' GROUP BY u.uid';
to
$sql .= ' GROUP BY u.uid, u.name, u.mail, u.status, t.ip_address, u.created';
and the resulting query is successful.
As a side note, GROUP BY including the ip_address will provide the extra benefit of breaking out the results of for a user by IP which can be helpful.
Comments
Comment #1
deekayen commentedApplied to DRUPAL-4-7 and DRUPAL-5.
Comment #2
(not verified) commented