Page 1 of 1

Issue with bigint unsigned

Posted: Sun Mar 26, 2006 2:30 am
by ibizconsultants
Can anyone help me with this...

I have a field

ratingtotal bigint unsigned

The issue is that when the field value is 10 and I use the following query

UPDATE table
set ratingtotal = ratingtotal - 20
WHERE...

The above case is hypothetical.... my issue is that when I do this, MySQL instead of assigning 0 to the field, it assigns the highiest value of BIGINT - 20.

I am totally stumped....

Thanks for reading.

Posted: Sun Mar 26, 2006 3:04 am
by feyd
makes perfect sense as that's how the operation would turn out in binary. I wouldn't expect MySQL to do range checking (as that can add a LOT to processing time)

Code: Select all

UPDATE `table`
SET `field` = IF(`field` < 20, 0, `field` - 20)
WHERE ...
may work.

Posted: Sun Mar 26, 2006 3:15 am
by ibizconsultants
Thanks feyd.... it works.