BIGINT UNSIGNED value is out of range in..的解決方法
阿新 • • 發佈:2019-01-10
今天在做一個功能的時候,用到兩個時間戳相減來做查詢條件,由於其兩個欄位都是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 inset (0.01 sec)
- mysql> select lastvisit-lastactivity from pre_common_member_status limit 1;
- +------------------------+
- | lastvisit-lastactivity |
- +------------------------+
-
| 863271 |
- +------------------------+
- 1 row inset (0.05 sec)
- mysql> selectabs(lastvisit-lastactivity) from pre_common_member_status limit 1;
- +-----------------------------+
- | abs(lastvisit-lastactivity) |
- +-----------------------------+
- | 863271 |
- +-----------------------------+
-
1 row in
- mysql> select lastactivity-lastvisit from pre_common_member_status limit 1;
- ERROR 1690 (22003): BIGINT UNSIGNED value isoutof range in '(`discuz`.`pre_c
- ommon_member_status`.`lastactivity` - `discuz`.`pre_common_member_status`.`las
- tvisit`)'
- mysql> selectcast(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 inset (0.02 sec)
- mysql> selectabs(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 inset (0.00 sec)
- mysql>