Bug #3384 Integer types cast
Submitted: 3 Apr 2004 23:15 Modified: 11 Aug 2005 17:35
Reporter: Andrey Oshemkov Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Documentation Severity:S4 (Feature request)
Version:4.0.16 OS:FreeBSD (FreeBSD)
Assigned to: CPU Architecture:Any

[3 Apr 2004 23:15] Andrey Oshemkov
Description:
When I cast from signed to unsigned, I need to work with 32-bit numbers. For example, 

mysql> select cast(-2164260863 as unsigned);
+-------------------------------+
| cast(-2164260863 as unsigned) |
+-------------------------------+
|          18446744071545290753 |
+-------------------------------+
1 row in set (0.01 sec)

but I need result like

mysql> select (-2164260863+0x100000000) % 0x100000000;
+-----------------------------------------+
| (-2164260863+0x100000000) % 0x100000000 |
+-----------------------------------------+
|                              2130706433 |
+-----------------------------------------+
1 row in set (0.00 sec)

How to repeat:
mysql> select cast(-2164260863 as unsigned);
+-------------------------------+
| cast(-2164260863 as unsigned) |
+-------------------------------+
|          18446744071545290753 |
+-------------------------------+
1 row in set (0.01 sec)

but I need result like

mysql> select (-2164260863+0x100000000) % 0x100000000;
+-----------------------------------------+
| (-2164260863+0x100000000) % 0x100000000 |
+-----------------------------------------+
|                              2130706433 |
+-----------------------------------------+
1 row in set (0.00 sec)

Suggested fix:
Please add to cast() option like cast(num as unsigned int(4)) or describe it in your documentation if it is realized now.

Thx for support ;)
[11 Aug 2005 17:35] Mike Hillyer
Sounds like you are trying to use CAST() as ABS().