mysqlboolean

MySQL boolean - flipping the value?


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


Solution

  • Why not simply use:

    UPDATE the_table
       SET boolean_field = NOT boolean_field
    WHERE ...
    

    Makes your intention a lot easier to read