我正在尝试创建一个临时表,将原始表中的char(10)数字tkey存储为无符号整数。 遇到第109516行时失败:
mysql> CREATE TEMPORARY TABLE IF NOT EXISTS lutemp AS (SELECT cast(tkey as unsigned),ca01,ce01 FROM lu); ERROR 1264 (22003): Out of range value for column 'cast(tkey as unsigned)' at row 109516
但是如果我选择该行作为强制转换为整数,那么它就没有问题:
mysql> select cast(tkey as unsigned) from lu limit 109515,1; +--------------------------+ | cast(tkey as unsigned) | +--------------------------+ | 4298001000 | +--------------------------+ 1 rows in set (0.10 sec)
我做错了什么?
答案 0 :(得分:1)
不要依赖数据库从BIGINT
为您提供CAST(... UNSIGNED)
。
UNSIGNED INT的最大值是
4,294,967,295
见here。你的价值是
4,298,001,000
尝试使用BIGINT UNSIGNED
显式:
CREATE TEMPORARY TABLE IF NOT EXISTS lutemp
(SELECT tkey, ca01,ce01 FROM lu LIMIT 0);
ALTER TABLE lutemp MODIFY tkey BIGINT UNSIGNED;
INSERT INTO lutemp (tkey, ca01,ce01)
SELECT tkey, ca01,ce01 FROM lu
;