This applies to version 2.2 as well:

Drupal configuration:

Acquia drupal 1.2 (6.8 core)
PostgreSQL 8.3

Problem: When adding a 'checkbox' filter from a profile field.
Diagnose:

1. PostgreSQL has strict data type enforcement, the table column 'value' from table {profile_values} is a type of text, the SQL syntax of WHERE profile_values_profile_partner_foggle_rolereg0.value <> 0 should be WHERE profile_values_profile_partner_foggle_rolereg0.value <> '0' to add explicit type casting

2. The sub-query SELECT COUNT(*) FROM (SELECT ....) also have the wrong syntax in postgreSQL, it needs to have an alias.

SELECT COUNT(*) FROM (SELECT ....) AS 'foo_bar'

I have attached the corrected SQL query for this error and, this query has been tested and it works.

Live SQL output:

    * warning: pg_query() [function.pg-query]: Query failed: ERROR: operator does not exist: text <> integer LINE 8: ...RE profile_values_profile_partner_foggle_rolereg0.value <> 0 ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. in /usr/local/apache2/htdocs/acdrupal/includes/database.pgsql.inc on line 139.
    * user warning: query: SELECT COUNT(*) FROM (SELECT users.uid AS uid FROM ac_users users LEFT JOIN ac_profile_values profile_values_profile_partner_foggle_rolereg0 ON users.uid = profile_values_profile_partner_foggle_rolereg0.uid AND profile_values_profile_partner_foggle_rolereg0.fid = '73' LEFT JOIN ac_profile_values profile_values_profile_first_name ON users.uid = profile_values_profile_first_name.uid AND profile_values_profile_first_name.fid = '1' LEFT JOIN ac_profile_values profile_values_profile_last_name ON users.uid = profile_values_profile_last_name.uid AND profile_values_profile_last_name.fid = '2' LEFT JOIN ac_profile_values profile_values_profile_company_website ON users.uid = profile_values_profile_company_website.uid AND profile_values_profile_company_website.fid = '19' LEFT JOIN ac_profile_values profile_values_profile_country ON users.uid = profile_values_profile_country.uid AND profile_values_profile_country.fid = '27' WHERE profile_values_profile_partner_foggle_rolereg0.value <> 0 ) count_alias in /usr/local/apache2/htdocs/acdrupal/modules/acquia/views/includes/view.inc on line 699.
    * warning: pg_query() [function.pg-query]: Query failed: ERROR: operator does not exist: text <> integer LINE 15: ...RE profile_values_profile_partner_foggle_rolereg0.value <> 0 ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. in /usr/local/apache2/htdocs/acdrupal/includes/database.pgsql.inc on line 139.
    * user warning: query: SELECT users.uid AS uid, users.name AS users_name, profile_values_profile_first_name.value AS profile_values_profile_first_name_value, profile_values_profile_last_name.value AS profile_values_profile_last_name_value, profile_values_profile_company_website.value AS profile_values_profile_company_website_value, profile_values_profile_country.value AS profile_values_profile_country_value, users.created AS users_created, users.login AS users_login FROM ac_users users LEFT JOIN ac_profile_values profile_values_profile_partner_foggle_rolereg0 ON users.uid = profile_values_profile_partner_foggle_rolereg0.uid AND profile_values_profile_partner_foggle_rolereg0.fid = '73' LEFT JOIN ac_profile_values profile_values_profile_first_name ON users.uid = profile_values_profile_first_name.uid AND profile_values_profile_first_name.fid = '1' LEFT JOIN ac_profile_values profile_values_profile_last_name ON users.uid = profile_values_profile_last_name.uid AND profile_values_profile_last_name.fid = '2' LEFT JOIN ac_profile_values profile_values_profile_company_website ON users.uid = profile_values_profile_company_website.uid AND profile_values_profile_company_website.fid = '19' LEFT JOIN ac_profile_values profile_values_profile_country ON users.uid = profile_values_profile_country.uid AND profile_values_profile_country.fid = '27' WHERE profile_values_profile_partner_foggle_rolereg0.value <> 0 LIMIT 10 OFFSET 0 in /usr/local/apache2/htdocs/acdrupal/modules/acquia/views/includes/view.inc on line 725.

Exported View:

$view = new view; 
$view->name = 'partner_lead'; 
$view->description = 'To show registered users who are interested in become partners'; $view->tag = 'partner lead'; 
$view->view_php = ''; $view->base_table = 'users'; $view->is_cacheable = FALSE; $view->api_version = 2; 
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ 
$handler = $view->new_display('default', 'Defaults', 'default'); 
$handler->override_option('fields', array( 'name' => array( 'id' => 'name', 'table' => 'users', 'field' => 'name', ), 'value_2' => array( 'id' => 'value_2', 'table' => 'profile_values_profile_first_name', 'field' => 'value', ), 'value_3' => array( 'id' => 'value_3', 'table' => 'profile_values_profile_last_name', 'field' => 'value', ), 'value' => array( 'id' => 'value', 'table' => 'profile_values_profile_company_website', 'field' => 'value', ), 'value_1' => array( 'id' => 'value_1', 'table' => 'profile_values_profile_country', 'field' => 'value', ), 'created' => array( 'label' => 'Join Date', 'date_format' => 'small', 'custom_date_format' => '', 'exclude' => 0, 'id' => 'created', 'table' => 'users', 'field' => 'created', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), 'login' => array( 'id' => 'login', 'table' => 'users', 'field' => 'login', ), )); $handler->override_option('arguments', array( 'value' => array( 'id' => 'value', 'table' => 'profile_values_profile_registration_source', 'field' => 'value', ), )); 
$handler->override_option('filters', array( 'value' => array( 'operator' => '=', 'value' => '1', 'group' => '0', 'exposed' => FALSE, 'expose' => array( 'operator' => FALSE, 'label' => '', ), 'id' => 'value', 'table' => 'profile_values_profile_partner_foggle_rolereg0', 'field' => 'value', 'relationship' => 'none', ), )); 
$handler->override_option('access', array( 'type' => 'none', ));
 $handler->override_option('use_pager', '1'); 
$handler->override_option('style_plugin', 'table'); 
$handler->override_option('style_options', array( 'grouping' => '', 'override' => 1, 'sticky' => 0, 'order' => 'asc', 'columns' => array( 'name' => 'name', 'value_2' => 'value_2', 'value_3' => 'value_3', 'value' => 'value', 'value_1' => 'value_1', 'created' => 'created', 'login' => 'login', 'rid' => 'rid', ), 'info' => array( 'name' => array( 'sortable' => 0, 'separator' => '|', ), 'value_2' => array( 'sortable' => 0, 'separator' => '|', ), 'value_3' => array( 'sortable' => 0, 'separator' => '|', ), 'value' => array( 'sortable' => 0, 'separator' => '|', ), 'value_1' => array( 'sortable' => 0, 'separator' => '|', ), 'created' => array( 'sortable' => 0, 'separator' => '|', ), 'login' => array( 'sortable' => 0, 'separator' => '|', ), 'rid' => array( 'separator' => '|', ), ), 'default' => '-1', )); 
$handler = $view->new_display('page', 'Page', 'page_1'); 
$handler->override_option('path', 'view/partner_lead'); 
$handler->override_option('menu', array( 'type' => 'none', 'title' => '', 'weight' => 0, 'name' => 'navigation', )); $handler->override_option('tab_options', array( 'type' => 'none', 'title' => '', 'weight' => 0, ));
CommentFileSizeAuthor
#17 views-420574-16.patch909 byteslaceysanderson
#6 views-420574.patch402 bytesgmh04
query_error.txt1016 bytesxcf33
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

-Mania-’s picture

Version: 6.x-2.3 » 6.x-2.8

I experienced the same problem using PostgreSQL 8.3.9 and Views 2.8.

I ended up using a 'selection' rather than 'checkbox' filter from a profile field which seems to work. Hopefully the 'checkbox' filter is fixed on upcoming Views versions.

Josh Waihi’s picture

This is because the profile handler used is views_handler_filter_boolean_operator which I imagine is normally used on numeric columns. MySQL naturally allows a numeric comparison to occur on a text column (go figure).

From the little analysis I did, I think another boolean comparison handler should be written for text column which only difference is adds the quotes around it. This would fix it in PostgreSQL.

Also for the subselect, aliases for the table should always be present. Views seems to have already addressed this:

includes/view.inc:724:        $count_query = 'SELECT COUNT(*) FROM (' . str_replace(array_keys($replacements), $replacements, $count_query) . ') count_alias';

So I'm not sure that views is causing this.

gmh04’s picture

I have the same problem using Postgres 8.3.8 and Views 6.x-2.1 using Profile checkboxes. This worked ok on Postgres 8.1.5 but will prevent me from upgrading to a newer version.

Has a solution been found for this?

gmh04’s picture

I 'fixed' this by quoting the 0 in the query() function of views_handler_filter_boolean_operator.inc

function query() {
    $this->ensure_my_table();

    $where = "$this->table_alias.$this->real_field ";

    if (empty($this->value)) {
      $where .= '= 0';
      if ($this->accept_null) {
        $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)";
      }
    }
    else {
      $where .= "<> '0'";
    }
    $this->query->add_where($this->options['group'], $where);
  }
Josh Waihi’s picture

true, infact maybe that should be the correct patch as MySQL will be ok with this, as will PostgreSQL. @gmh04, can you write a patch for that change?

gmh04’s picture

FileSize
402 bytes

sure.

mcrittenden’s picture

Status: Active » Needs review
dawehner’s picture

Do i see it true, that if you have a numeric value in the database this will fail?

I'm not familiar with pgsql.

Josh Waihi’s picture

@dereine, PostgreSQL will accept 123 and '123' as valid numeric values. It doesn't, however, accept '12.3' as a valid float.

Letharion’s picture

Assigned: Unassigned » dawehner

@dereine
Since you've gotten started with this one, I'm assigning it to you.
If it helps, I could probably hook you up with a pgsql db.

merlinofchaos’s picture

Status: Needs review » Postponed (maintainer needs more info)

If <> 0 fails and <> '0' succeeds, why does = 1 succeed?

Also, is this patch related? http://drupal.org/node/416178

I just realized I lost a bunch of time trying to replicate this issue and found that the version of postgres I have on CentOS 5 is too old to exhibit this behavior. Sigh.

esmerel’s picture

Anyone with this problem want to take another crack before I close the issue?

esmerel’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
darksatanic’s picture

Status: Closed (cannot reproduce) » Reviewed & tested by the community

I can reproduce this error, as I've just stumbled over it.

I can confirm that gmh04's patch seems to work OK for me -- it's taken the bug away.

dawehner’s picture

Status: Reviewed & tested by the community » Active

Well based on http://drupal.org/node/420574#comment-3833426 i think RTBC is the wrong status.

laceysanderson’s picture

This error is Very reproducible.

I installed a clean drupal 6.22 with postgresql 8.4.7 backend. I git cloned and enabled views 6.x-2.x and also enabled the core Profile module. I created a single profile checkbox.

I can create a view that displays the user name and value of this checkbox with no errors.
SQL: SELECT users.uid AS uid, users.name AS users_name, profile_values_profile_test_checkbox.value AS profile_values_profile_test_checkbox_value FROM users users LEFT JOIN profile_values profile_values_profile_test_checkbox ON users.uid = profile_values_profile_test_checkbox.uid AND profile_values_profile_test_checkbox.fid = '1'
Resulting Table:

User Personal Information: Test Checkbox
test_user1 Yes
test_user2 No
test_user3 No
test_user4 Yes

However, after adding a filter for that checkbox being True, I get the following error:
warning: pg_query() [function.pg-query]: Query failed: ERROR: operator does not exist: text <> integer LINE 6: WHERE profile_values_profile_test_checkbox.value <> 0 ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. in /var/www/drupal-6.22/includes/database.pgsql.inc on line 138.

user warning: query: SELECT users.uid AS uid, users.name AS users_name, profile_values_profile_test_checkbox.value AS profile_values_profile_test_checkbox_value FROM users users LEFT JOIN profile_values profile_values_profile_test_checkbox ON users.uid = profile_values_profile_test_checkbox.uid AND profile_values_profile_test_checkbox.fid = '1' WHERE profile_values_profile_test_checkbox.value <> 0 LIMIT 4 OFFSET 0 in /var/www/drupal-6.22/sites/all/modules/views/includes/view.inc on line 810.

I get a very similar error (instead of <> 0 it becomes = 0) when I change the filter to False.

I tried applying the above patch but received an error when applying in modules/views that the file wasn't found and and error while searching for... when applying in the handlers directory. As such I made the changes to my views manually...

@@ -141,17 +141,17 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
     $where = "$this->table_alias.$this->real_field ";
 
     if (empty($this->value)) {
-      $where .= '= 0';
+      $where .= "= '0'";
       if ($this->accept_null) {
         $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)";
       }
     }
     else {
       if (!empty($this->definition['use equal'])) {
-        $where .= '= 1';
+        $where .= "= '1'";
       }
       else {
-        $where .= '<> 0';
+        $where .= "<> '0'";
       }
     }
     $this->query->add_where($this->options['group'], $where);

Now my view works perfectly both when the checkbox filter is selected to be True and when it's selected to be false.

laceysanderson’s picture

FileSize
909 bytes

Attaching the new Patch.

laceysanderson’s picture

Version: 6.x-2.8 » 6.x-2.x-dev
Status: Active » Needs review

Since there is a new patch, I think the status should be changed to Needs Review.

laceysanderson’s picture

I've also tested this patch on MySQL and it works beautifully -no errors.

Used the same directory structure as above but changed the backend. Mysql server version 5.1.49-3 (Debian). Re-did install.php and enabled profile and views. Created the same profile checkbox and the same 4 dummy users. Then imported the view tested on my postgresql backend.

Hopefully testing it on both MySQL and postgreSQL myself will speed up the incorporation of this patch since I really need it for my production site... If I can do anything else -just shout :)
~Lacey

timofey’s picture

I'm not sure if it's related, but in drupal 7, filtering by checkmark by "Is not one of" (<>) brings up no results, while "Is one of" (=) works fine.

MustangGB’s picture

Status: Needs review » Closed (won't fix)