MySQL uses TinyINT to serve as a boolean field. Given the possible options of 0 and 1, I decided that I'd flip values like this:
UPDATE table
SET boolean_field = ABS(boolean_field - 1)
WHERE Circle-K = 'Strange things are afoot'
So you either go 1 -> 0 -> ABS(0) = 0
or 0 -> -1 -> ABS(-1) = 1
now I'm curious if this is acceptable or horrifying to the real programmers?
/me is a beginner
You can use Boolean Operator for this Here delete is your boolean field. This solution also works for none boolean fields such as int and tinyint where values are set to 0 or 1.
Yes, MySQL internally convert bool to tinyint(1) because tinyint is the smallest integer data type.
You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).
In MySQL, TINYINT(1) and boolean are synonymous. Because of this, the MySQL driver implicitly converts the TINYINT(1) fields to boolean if the the Java tinyInt1isBit configuration property is set to true (which is the default) and the storage size is 1. Stitch then interprets these columns as BIT(1)/boolean .
Why not simply use:
UPDATE the_table SET boolean_field = NOT boolean_field WHERE ...
Makes your intention a lot easier to read
You can also use field
= 1 - field
or field
= ! field
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With