BIGINT UNSIGNED value is out of range in..的解决方法

Posted on   jiaoqing。  阅读(499)  评论(0编辑  收藏  举报

今天在做一个功能的时候,用到两个时间戳相减来做查询条件,由于其两个字段都是unsigned的,并两个的大小是不一样。所以直接相减查询的时候,

就出现ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in..的错误,因为结果可能会出现负数。。。。

过后查资料,发现可以通过下面的方法来解决:

 

复制代码
mysql> select lastvisit, lastactivity from pre_common_member_status limit 1;  
+------------+--------------+  
| lastvisit  | lastactivity |  
+------------+--------------+  
| 1199200260 |   1198336989 |  
+------------+--------------+  
1 row in set (0.01 sec)  
  
mysql> select lastvisit-lastactivity from pre_common_member_status limit 1;  
+------------------------+  
| lastvisit-lastactivity |  
+------------------------+  
|                 863271 |  
+------------------------+  
1 row in set (0.05 sec)  
  
mysql> select abs(lastvisit-lastactivity) from pre_common_member_status limit 1;  
  
+-----------------------------+  
| abs(lastvisit-lastactivity) |  
+-----------------------------+  
|                      863271 |  
+-----------------------------+  
1 row in set (0.03 sec)  
  
mysql> select lastactivity-lastvisit from pre_common_member_status limit 1;  
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`discuz`.`pre_c  
ommon_member_status`.`lastactivity` - `discuz`.`pre_common_member_status`.`las  
tvisit`)'  
mysql> select cast(lastactivity as signed)-cast(lastvisit as signed) from pre_co  
mmon_member_status limit 1;  
+--------------------------------------------------------+  
| cast(lastactivity as signed)-cast(lastvisit as signed) |  
+--------------------------------------------------------+  
|                                                -863271 |  
+--------------------------------------------------------+  
1 row in set (0.02 sec)  
  
mysql> select abs(cast(lastactivity as signed)-cast(lastvisit as signed)) from p  
re_common_member_status limit 1;  
+-------------------------------------------------------------+  
| abs(cast(lastactivity as signed)-cast(lastvisit as signed)) |  
+-------------------------------------------------------------+  
|                                                      863271 |  
+-------------------------------------------------------------+  
1 row in set (0.00 sec)  
  
mysql>  
复制代码

 

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?

随笔 - 287, 文章 - 0, 评论 - 3, 阅读 - 42万

Copyright © 2025 jiaoqing。
Powered by .NET 9.0 on Kubernetes

点击右上角即可分享
微信分享提示