I'm in the process of trying to get this module to work with PostgreSQL. In the logs, I'm seeing these errors:
pg_query(): Query failed: ERROR: column "advagg_bundles.filename_md5" must appear in the GROUP BY clause or be used in an aggregate function LINE 4: SELECT * ^ in [path_to_drupal]/includes/database.pgsql.inc on line 138.
query: SELECT COUNT(*) FROM ( SELECT * FROM advagg_bundles WHERE timestamp < 1317347113 GROUP BY bundle_md5 ) AS advagg_count in [path_to_drupal]/sites/all/modules/advagg/advagg.module on line 315.
The offending SQL seems to be
$bundles_removed += db_result(db_query("
SELECT COUNT(*)
FROM (
SELECT *
FROM {advagg_bundles}
WHERE timestamp < %d
GROUP BY bundle_md5
) AS advagg_count", $max_bundle_time));
Unless I'm missing something, can't we get rid of the sub-select and just write it as the following?
$bundles_removed += db_result(db_query("
SELECT COUNT(*) AS advagg_count
FROM {advagg_bundles}
WHERE timestamp < %d
GROUP BY bundle_md5", $max_bundle_time));
Patch attached.
Comments
Comment #1
mikeytown2 commentedDidn't see this as it wasn't set to needs review.
Comment #2
mikeytown2 commentedYour patch doesn't work correctly.
returns 1,044
returns 1,044 ROWS.
Can you try this query?
Comment #3
ChrisLaFrancis commentedI actually disabled the module for now as there were several other PostgreSQL-related incompatibilities that I just don't have the time to work through at the moment. When I get a little time in the near future, I'll give it a try again.
Comment #4
ChrisLaFrancis commentedI haven't tested anything, but just going by what you wrote, I think the difference you're seeing ("1044" vs "1044 ROWS") is just how whatever SQL client you're using is formatting the result of count(). Count() only returns a number, not the actual rows or the number of rows with the string "ROWS" appended to it.
In PostgreSQL, these two queries return the exact same result:
This query, however, which is selecting the count() of a subquery with a count(), only returns one row, because the result of from count() is really just one row with the lone value of 28.
Comment #5
mikeytown2 commentedI mean it returns 1,044 different values. The original query returns one value. The way the code is written, it is expecting only one value.
Comment #6
ChrisLaFrancis commentedI'm curious now, and I would really like to be able to use this module. I'll try to look at this later tonight.
Comment #7
ChrisLaFrancis commentedI see what you're saying now. My mistake. I think the problem is that since it's using the GROUP BY, it's giving us a count of the occurrences of each distinct value. Here is the new query using a DISTINCT in the COUNT() instead of a GROUP BY:
Patch attached.
Comment #8
mikeytown2 commentedThanks! Patch above has been committed.