- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
create table test(
id integer primary key auto_increment,
d datetime not null
);
insert into test(id) values (1);
-- а сейчас я покажу вам особую уличную магию
select *, d is null, d is not null from test;
select *, d is null, d is not null from test
where d is not null;
select *, d is null, d is not null from test
where d is null; -- WTF?!
select *, d is null, d is not null from test
where d is not null and d is null; -- WTF?!
Все 4 select'а выводят одинаковый результат... MySQL такой MySQL...
P.S. Вставка всякой херни вместо вывода ошибки лечится добавлением STRICT_ALL_TABLES в sql_mode. А вот where с нулевой датой не лечится, видимо, это баг движка.
Да тут целая кунсткамера! Оказывается, сейчас мускуль еще более-менее юзабельный... Судя по режимам совместимости раньше было еще хуже...
From MySQL 5.0.2 on, the precedence of the NOT operator is such that expressions such as NOT a BETWEEN b AND c are parsed as NOT (a BETWEEN b AND c). Before MySQL 5.0.2, the expression is parsed as (NOT a) BETWEEN b AND c.
Do not perform full checking of dates. Check only that the month is in the range from 1 to 12 and the day is in the range from 1 to 31. This is very convenient for Web applications where you obtain year, month, and day in three different fields and you want to store exactly what the user inserted (without date validation). Before 5.0.2, this was the default MySQL date-handling mode.
Treat || as a string concatenation operator (same as CONCAT()) rather than as a synonym for OR.
Как говорил guest, Шрёдингер, мы нашли твоего кота!
PS: Что-то я нахимичил когда писал вопрос...
- Папа, а стандарт SQL существует?
- Нет сынок, это фантастика.
Да чё тут непонятного - legacy. Либо ломаем совместимость со старым кодом, юзающим нашу базу, либо ломаем совместимость с другими базами (и стандартом). Само собой все мало-мальски взрослые СУБД выбрали первое. И винить их за это нельзя...
А у мускуля свои тараканы - у них вообще был только нетранзакционный движок. И часть отклонений и извращений унаследованы от него.