After installing quotes.module (Druapl 6.19, PostgreSQL 8.1.21), when I got to add my first block ( /admin/build/block/configure/quotes/1 ), I get this:

* warning: pg_query() [function.pg-query]: Query failed: ERROR: column "qa.aid" must appear in the GROUP BY clause or be used in an aggregate function in /var/www/drupal-6.19/includes/database.pgsql.inc on line 139.
* user warning: query: SELECT qa.aid, qa.name, COUNT(q.nid) as count FROM quotes_authors qa LEFT JOIN quotes q USING(aid) GROUP BY qa.name ORDER BY qa.name in /var/www/drupal-6.19/sites/all/modules/quotes/quotes.module on line 1647.

The way that GROUP BY is used here is not supported in PostgreSQL, it seems to be non-standard. Some information on this here:

http://archives.postgresql.org/pgsql-general/2004-02/msg01198.php

Changing line 1646 to

$result = db_query('SELECT qa.aid, qa.name, COUNT(q.nid) as count FROM {quotes_authors} qa LEFT JOIN {quotes} q USING(aid) GROUP BY qa.name, qa.aid ORDER BY qa.name');

seems to work ok.

The problem is that an SQL statement like

select a,b from foo group by a

is ambiguous; if you've got a table foo

a b
------------------
1 apple
1 banana
2 cherry

what value for b should appear in the returned row where a=1? Do we get

1 apple
2 cherry

or

1 banana
2 cherry

MySQL allows this -- I don't know if it picks a row at random, or the "first" one according to some ordering scheme, or what -- but this is another way that MySQL should be Considered Harmful. :-)

Comments

nancydru’s picture

Status: Active » Fixed

This makes no sense to me. The aid in the quotes_author table is serial (therefore unique). Further, name is one-to-one with it.

Since it doesn't seem to break MySql, I made the change and committed it to 6.x-1.x-dev. Please test it and let me know.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.