Hello

I am using drupal 6.10 with postgresql 8.3 and I get this error when trying to get the "Top visitors in the past 4 weeks" report:

* warning: pg_query() [function.pg-query]: Query failed: ERROR: function concat(int_unsigned, character varying) does not exist LINE 1: SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM accesslog ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. in /var/www/drupal-6.10-www/includes/database.pgsql.inc on line 139.
   
* user warning: query: SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM accesslog in /var/www/drupal-6.10-www/modules/statistics/statistics.admin.inc on line 87.

Since the last version of postgresql (8.3) was released, it does not work anymore to used implicit type cast. You (as a programmer) has to decide what your data is going to be convert to.

To fix this error change modules/statistics/statistics.admin.inc on line 87 from:

$sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog}";

to:

$sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid::text, hostname))) FROM {accesslog}";

--- /local/var/www/drupal-6.10-www/modules/statistics/statistics.admin.inc~     2008-01-08 10:35:42.000000000 +0000
+++ /local/var/www/drupal-6.10-www/modules/statistics/statistics.admin.inc      2009-03-24 17:35:57.000000000 +0000
@@ -83,7 +83,7 @@
   );
 
   $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, ac.aid FROM {accesslog} a LEFT JOIN {access} ac ON ac.type = 'host' AND LOWER(a.hostname) LIKE (ac.mask) LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, ac.aid". tablesort_sql($header);
-  $sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog}";
+  $sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid::text, hostname))) FROM {accesslog}";
   $result = pager_query($sql, 30, 0, $sql_cnt);
 
   $rows = array();

regards
Rafael Martinez

CommentFileSizeAuthor
#1 statistics.admin_.inc_.patch773 byteslifepillar
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lifepillar’s picture

FileSize
773 bytes

I confirm the bug. Unfortunately, the proposed patch is not compatible with MySQL. Attached you find a patch that work both in MySQL and PostgreSQL.

Btw, this problem exists at least since 6.8: I hope the following release will fix it!

lifepillar’s picture

Status: Active » Patch (to be ported)

Sorry, I forgot to set the status to patch (to be ported).

lifepillar’s picture

Status: Patch (to be ported) » Closed (duplicate)

I have just noticed that this a duplicate of http://drupal.org/node/229051.