Does Drupal 7's DB API support SQL's CAST function? I have a varchar with numbers in it that I'm trying to convert to integers for proper sorting. Here's my statement:
$images = db_query('SELECT filename, caption FROM {iha_captions}
WHERE uid = :uid ORDER BY CAST(weight AS INT) ASC', array(':uid' => $userid));
And here is the error I get:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT) ASC' at line 1: SELECT filename, caption FROM {iha_captions} WHERE uid = :uid ORDER BY CAST(weight AS INT) ASC; Array ( [:uid] => 2814 ) in iha_search_profile()
It then causes a cascade of SQL failures in Drupal's session and cache queries. Is CAST
supported, or am I doing it wrong?