MySQL版本:5.5.38-0ubuntu0.14.04.1ERROR 1690(22003):BIGINT UNSIGNED值超出範圍在
表結構:
CREATE TABLE `route_points2` (
`dist` tinyint(4) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
內容:1行與dist
等於至200
SQL:
SELECT * FROM route_points2 WHERE -1*dist < 1;
錯誤:
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(<cache>(-(1)) * `db_name`.`route_points2`.`dist`)'
爲什麼mysql將-1*dist
轉換爲BIGINT UNSIGNED
?
上述錯誤可以通過鑄造dist
到SIGNED
解決:
SELECT * FROM route_points2 WHERE -1*CAST(dist AS SIGNED) < 1;
這工作得很好。
但我不明白爲什麼MySQL的選擇BIGINT UNSIGNED
爲-1*dist
可避免類似的'CAST':'''SELECT * FROM'route_points2' WHERE -'dist' <1;''' – wchiquito 2014-09-11 14:12:20
它簡化例子。在現實世界中,它不僅是符號反轉。 – Index 2014-09-11 18:44:59
像https://stackoverflow.com/questions/5605085/bigint-unsigned-value-is-out-of-range – qdinar 2017-07-13 09:35:57