var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Whats the best datatype to use for boolean data?
I need a column for status that takes only one of two values, 0 or 1. I also need a way to flip the status (similar to binary bit compliment) from 0 to 1 or 1 to 0. Can I do this in MySql? Some thing like Update _tbl set flag=!flag?
look on the manual at the
bit data type
And as for complimenting the boolean; I think the answer in MySQL is to use the bang (!) symbol
reason? it is the easiest datatype to upgrade to 3 values (e.g. 0,1,2) with the least impact on application code
to flip the status, use
SET status = CASE WHEN status = 1 THEN 0 ELSE 1 END
Argueably, bit allows for 3 values, the third being the absence of a value, but a fair point nonetheless.
I tried the bang (!) on tinyint I dont think it works. I ll try it on bit datatypes.
Thanks everyone for your help.
Failing that, try the tilde (~)
Let us know how you get on
The ! doesnt work, but ~ seems to work but is behaving funny. It flipped a b'0' to b'1' but could not flip a 1 back. Must be something I am doing wrong. Anyways I opted to use tinyint(1)
with "UPDATE daTable
SET status = CASE WHEN status = 1 THEN 0 ELSE 1 END" for flipping bits as r937 suggested.
I always thought the absence of a value is represented with NULL in an RDBMS...
Originally Posted by
That's what I was hinting at shammat, but I see your finicky point