MYSQL 竟然 溢出了 第一次发现 呵呵

wdvill 2010-08-10 04:32:45


竟然还有这情况

SELECT `bxd_id` , ABS( ent_id - area_id ) AS `wang`
FROM `gx_bxd_iw`
WHERE 1
LIMIT 0 , 30

上面是我的SQL语句

第一次看到这样
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
netxuning 2010-08-17
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wdvill 的回复:]

引用 4 楼 loveflea 的回复:

有unsigned的,默认模式下,可能会溢出,呵呵!

SQL code

mysql> create table unsigned_test(end_id integer unsigned,start_id integer unsig
ned);
Query OK, 0 rows affected (0.16 sec)

mysq……
[/Quote]

对,实践者万岁!
feixianxxx 2010-08-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 loveflea 的回复:]

有unsigned的,默认模式下,可能会溢出,呵呵!

SQL code

mysql> create table unsigned_test(end_id integer unsigned,start_id integer unsig
ned);
Query OK, 0 rows affected (0.16 sec)

mysql> insert into unsigned_test ……
[/Quote]
学习下
loveflea 2010-08-16
  • 打赏
  • 举报
回复
参考
no_unsigned_subtraction
http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html#sqlmode_no_unsigned_subtraction

MySQL supports arithmetic with both signed and unsigned 64-bit values. If you are using numeric operators (such as + or -) and one of the operands is an unsigned integer, the result is unsigned. You can override this by using the SIGNED and UNSIGNED cast operators to cast the operation to a signed or unsigned 64-bit integer, respectively.
mysql> SELECT CAST(1-2 AS UNSIGNED)
-> 18446744073709551615
mysql> SELECT CAST(CAST(1-2 AS UNSIGNED) AS SIGNED);
-> -1
Note that if either operand is a floating-point value, the result is a floating-point value and is not affected by the preceding rule. (In this context, DECIMAL column values are regarded as floating-point values.)
mysql> SELECT CAST(1 AS UNSIGNED) - 2.0;
-> -1.0
If you are using a string in an arithmetic operation, this is converted to a floating-point number.
wdvill 2010-08-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 loveflea 的回复:]

有unsigned的,默认模式下,可能会溢出,呵呵!

SQL code

mysql> create table unsigned_test(end_id integer unsigned,start_id integer unsig
ned);
Query OK, 0 rows affected (0.16 sec)

mysql> insert into unsigned_test ……
[/Quote]
顶LS
实践者万岁
loveflea 2010-08-16
  • 打赏
  • 举报
回复
有unsigned的,默认模式下,可能会溢出,呵呵!


mysql> create table unsigned_test(end_id integer unsigned,start_id integer unsig
ned);
Query OK, 0 rows affected (0.16 sec)

mysql> insert into unsigned_test values(0,15);
Query OK, 1 row affected (0.03 sec)

mysql> select * from unsigned_test;
+--------+----------+
| end_id | start_id |
+--------+----------+
| 0 | 15 |
+--------+----------+
1 row in set (0.00 sec)

mysql> select end_id,start_id,(end_id-start_id) from unsigned_test;
+--------+----------+----------------------+
| end_id | start_id | (end_id-start_id) |
+--------+----------+----------------------+
| 0 | 15 | 18446744073709551601 |
+--------+----------+----------------------+
1 row in set (0.02 sec)
mysql> select cast(0 as unsigned)-15;
+------------------------+
| cast(0 as unsigned)-15 |
+------------------------+
| 18446744073709551601 |
+------------------------+
1 row in set (0.00 sec)
ACMAIN_CHM 2010-08-10
  • 打赏
  • 举报
回复
显然不是MYSQL的问题。

用MYSQL命令行直接试一下,排除你软件的干扰,另外desc `gx_bxd_iw` 贴出来看一下。
feixianxxx 2010-08-10
  • 打赏
  • 举报
回复
ent_id - area_id
这2个什么字段类型
vga 2010-08-10
  • 打赏
  • 举报
回复
能否确定是 mysql 问题还是客户端软件问题?

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧