tags:

views:

36

answers:

2

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

A: 

You can also use field = 1 - field or field = ! field

zerkms
+3  A: 

Why not simply use:

UPDATE the_table
   SET boolean_field = NOT boolean_field
WHERE ...

Makes your intention a lot easier to read

a_horse_with_no_name
+1 for added readability while (probably) not sacrificing speed.
paxdiablo
+1: Didn't know that was valid - confirmed on 4.1
OMG Ponies