Bug #27542 CAST() Function to Integer(10)
Submitted: 30 Mar 2007 9:08 Modified: 26 Apr 2007 11:25
Reporter: Paul van Keulen Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:5.0.24 OS:Any (2.6.17-gentoo-r8-va)
Assigned to: CPU Architecture:Any
Tags: CAST(), INT(10)

[30 Mar 2007 9:08] Paul van Keulen
Description:
I am building an application for different databases i.e. Oracle, MSSQL and of course MySQL.
 
In the version 5.0.24 of MySQL the following won't work:
select cast(null as int) as orderId from Orders;

I need this because in my program i expect an int32 and MySQL forces me to use an int64. 

How to repeat:
SELECT CAST(null as int) AS orderId FROM Orders;

Suggested fix:
I hope more datatypes for the CAST() funtion can be included.
[26 Apr 2007 11:25] Valeriy Kravchuk
Please, use SIGNED [INTEGER] or UNSIGNED type to cast:

mysql> select cast(null as signed) a;
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

mysql> select cast(null as unsigned) a;
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html
[2 Dec 2008 18:59] matthew montgomery
UNSIGNED is still not good enough, we need to be able to cast to all integral types. if you actually read the post, COUNT is returning int64 (UNSIGNED OR SIGNED) and c# applications expect an Int32...and throw an invalid cast exception when trying to unbox an object returned from COUNT() to type (int).