2016-01-23 86 views
1

我試圖創建一個臨時表,將原始表中的char(10)數字tkey存儲爲無符號整數。 當它遇到109516列。這將失敗:MySQL嘗試創建具有大整數的臨時表失敗

 
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 

但如果我選擇該行作爲轉換成integer,它有沒有問題,這樣做:

 
mysql> select cast(tkey as unsigned) from lu limit 109515,1; 


+--------------------------+ 
| cast(tkey as unsigned) | 
+--------------------------+ 
|    4298001000 | 

+--------------------------+ 
1 rows in set (0.10 sec) 

我在做什麼錯?

回答

1

不要依靠數據庫給 。

最大價值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 
; 
+0

謝謝,非常完美。 --trl – thelma