星期五的時候發現下面這個 SQL 語法在 MySQL 4 是正常的,但是到 MySQL 5 就出現 Out of range 的錯誤。
UPDATE products, orders_products
SET products.quantity = products.quantity - orders_products.quantity
WHERE products.id = orders_products.product_id
AND orders_products.order_id='xxx'
(後來查出是紅字的部份有問題)
因為 orders_products.quantity 的 Int 型態是 UNSIGNED ,而 products.quantity 不是。雖然這個語法不會去更新 orders_products.quantity 這個欄位,也不會讓 orders_products.quantity 產生負數,但是 MySQL 5 似乎會去檢查這個語句的型態。