View Full Version : update int field that is null
04-07-2009, 02:14 AM
Update table set field= field+1 where id = '74'
Field is type INTEGER
if initial field = null --> no error , no update.
Any comment on that
Take a look at the MySQL page entitled "problems with NULL values (http://dev.mysql.com/doc/refman/5.1/en/problems-with-null.html)".
Basically, any expression with a NULL value ends with a NULL value. In your case, you state that the field is NULL when you start the UPDATE. Adding any value to a NULL is NULL. Thus, the field is technically updating, it's just staying NULL. Make sense?
04-07-2009, 03:19 AM
There is, however, an easy fix:
UPDATE table SET field = IFNULL(field,0) + 1 WHERE id = '74';
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.