I want to try doing Mysql Casting in my query by db_select but face to error,

          $q->join('field_data_field_cinema_type', 'fct', 'fct.entity_id = n.nid');
          $q->condition('cast(n.nid AS SIGNED )',11517,'>'); // also $q->condition('cast(n.nid AS SIGNED INTEGER )',11517,'>');
     $res= $q->orderBy('nid')->execute()->rowCount();

and query string

SELECT n.nid AS nid, n.type AS type FROM {node} n INNER JOIN {field_data_field_cinema_type} fct ON fct.entity_id = n.nid WHERE (n.type IN (:db_condition_placeholder_0)) AND (fct.field_cinema_type_tid = :db_condition_placeholder_1) AND (castn.nidASSIGNEDINTEGER > :db_condition_placeholder_2)

My question is how can I use Mysql Casting in db_select?Is that supported in db_select or I should use db_query on EntityQuery ?


You can use the where() method for a SelectQuery:

$q->where('CAST(n.nid AS SIGNED) > :nid', array(':nid' => 11517));

So the choice is yours which type of query to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.