I liked Shlomi Noach post on “IS TRUE and IS FALSE“. This kind of logic create bugs.
What will this return?
select if((1 = true) and ( 1 is TRUE) and (NULL is not TRUE), TRUE, FALSE) as answer;
You should know,
NULL is never TRUE or FALSE but
NULL is always NOT TRUE or NOT FALSE.
NULL is a little like a vacuum. Ancient Greek philosophers did not like to admit the existence of a vacuum, asking themselves “how can ‘nothing’ be something?”. Does GOD exist in NULL?
If select “” is NOT NULL; is TRUE what is “”?
select "" is NOT NULL; +----------------+ | "" is NOT NULL | +----------------+ | 1 | +----------------+
Is the lack of an answer, an answer? Is the lack of datum, DATA? Or should it be “”. Should we record the blank spaces?
Given:
Create Table |
CREATE TABLE `test` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `data` varchar(16) DEFAULT NULL, KEY `id` (`id`) ) ENGINE=InnoDB |
When should this happen?
for x = 1 to X;
INSERT INTO `test`(`data`) VALUES ( NULL);
next x;
Null happens.
Tweet