* warning: pg_query() [function.pg-query]: Query failed: ERROR: column "user_stats_ips.first_seen_timestamp" must appear in the GROUP BY clause or be used in an aggregate function in /home/forum/drupal-6.10/includes/database.pgsql.inc on line 139.
    * user warning: query: SELECT MAX(ip_address) FROM user_stats_ips WHERE uid = 1 ORDER BY first_seen_timestamp in /home/forum/drupal-6.10/sites/all/modules/user_stats/user_stats.module on line 98.

Comments

grub3’s picture

What does MAX(ip_address) address for?
No? In fact, I don't understand the meaning of this SQL query.
Could you explain what it does ?

In user_stats.module, this is this line:

$query = db_query("SELECT MAX(ip_address)
        FROM {user_stats_ips} WHERE uid = %d
        ORDER BY first_seen_timestamp", $uid);

I think the SQL command **could be*** wrong in both MySQL and PostgreSQL.

The SQL command is trying to select the fist row. This should be:

$query = db_query("SELECT ip_address
        FROM {user_stats_ips} WHERE uid = %d
        ORDER BY first_seen_timestamp LIMIT 1", $uid);
grub3’s picture

Status: Active » Reviewed & tested by the community

Status patch reviewed by the community.

grub3’s picture

Status: Reviewed & tested by the community » Needs review
$query = db_query("SELECT ip_address
        FROM {user_stats_ips} WHERE uid = %d
        ORDER BY first_seen_timestamp LIMIT 1", $uid);

The original query may be wrong, we are not trying to select the maximum value of an IP, but the first row.

jaydub’s picture

I ran into this as well. The GROUP BY problem is typical in PostgreSQL since MySQL conveniently ignores what is normally bad logic when GROUP BYs are involved.

I too however was wondering what the rationale for the MAX(ip_address) call was. It seems to me that the desired behavior is to return the most recently used IP address which as others above have pointed out can be done with an ORDER BY and LIMIT.

wa2nlinux’s picture

Ok it seem to be work :D, I'll report if anything goes wrong

Liam McDermott’s picture

Status: Needs review » Fixed

Fixed. Thanks. :)

wa2nlinux’s picture

Status: Fixed » Active

Wait ... seem still error on it

# user warning: Statistic "ip_address" does not exist. in /home/forum/drupal-6.10/sites/all/modules/user_stats/user_stats.module on line 168.
wa2nlinux’s picture

Status: Active » Fixed

Error was gone using dev version

Status: Fixed » Closed (fixed)

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