Issue with bigint unsigned

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ibizconsultants
Forum Commoner
Posts: 35
Joined: Tue Sep 07, 2004 12:07 pm

Issue with bigint unsigned

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ibizconsultants
Forum Commoner
Posts: 35
Joined: Tue Sep 07, 2004 12:07 pm

Post by ibizconsultants »

Thanks feyd.... it works.
Post Reply