Archive for the ‘datatypes’ Category

Are bools bools in MySQL?

Март 6th, 2010

Are bools bools in MySQL - no they're not! Lets show this:


mysql> CREATE TABLE healthcheck ( isworking bool ) ENGINE=MEMORY;
Query OK, 0 rows affected (0.14 sec)



mysql> show create table healthcheck\G

*************************** 1. row ***************************

Table: healthcheck

Create Table: CREATE TABLE `healthcheck` (

`isworking` tinyint(1) DEFAULT NULL

) ENGINE=MEMORY DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

So a 'bool' in MySQL is actually a signed tinyint that has range -128 to 127. This information is actually hidden away in the bowels of the MySQL documentation at:
"[bool] These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true "
Why a bool would not be a synonym for bit(1) just escapes me!

PlanetMySQL Voting: Vote UP / Vote DOWN