is a microblog
home archives search feed blogroll

Fancy Trick For DBMS With No Bool Support

Declare your flag as such.


If you want your flag to be true, set it as such.

my_flag = ''

If you want your flag to be false, set it as such.

my_flag = NULL

Then you can check your flag using -

my_flag IS NOT NULL

- or -

my_flag IS NULL

This is described in the book High Performance MySQL: Optimization, Backups, Replication, and More.

My preferred way has always been to use CHAR(1) with T/F’ or Y/N’. It’s also possible to use a TINYINT with 0/1’. My method is more readable and obvious, but it is also slower.

Posted on 2018-02-09   #database     #sql  

← Next post    ·    Previous post →