Hi there,
I've just installed this module and found this error message after making a field unique and case insensitive:

warning: pg_query(): Query failed: ERROR: column "occurrences" does not exist LINE 5: HAVING occurrences > 1 ^ in drupal-6.25/includes/database.pgsql.inc on line 138.
user warning: query: SELECT COUNT(value) AS occurrences, value FROM profile_values WHERE fid = 1 GROUP BY LOWER(value) HAVING occurrences > 1 in drupal-6.25/sites/all/modules/unique_profile_field/unique_profile_field.module on line 134.

Just testing with PostgreSQL I get the desired result with the query:

    $result = db_query('SELECT occurrences, my_value AS value
                        FROM (
                           SELECT COUNT(value) AS occurrences, LOWER(value) AS my_value
                           FROM {profile_values} 
                           WHERE fid = %d
                           GROUP BY my_value    
                           HAVING COUNT(LOWER(value)) > 1   
                        ) AS tmp', $profile_field_id);

The problem is that 'occurrences' is not accessible from within the same query, so you need to declare a different HAVING clause. I declare an extra 'my_value' to ensure GROUP BY groups by the lowered version of 'value' (don't know if that is really needed). And this is the reason for subquerying all of this: ensure all columns have the name it's expected.

It's possible that the first query (the case sensitive one) also needs some remaking. I don't know if this technique also works for MySQL or SQLite or if there is a Drupal way to solve this kind of cases.

Best regards,
emi

Comments

v-a-1’s picture

Status: Active » Closed (fixed)

This should no longer be a problem from 6.x-1.1 release.

liam morland’s picture