1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
MySQL > select * from luxes where id = '657';
+-----+---------------------+------+---------------------+---------------------+
| id | recorded_at | lux | created_at | updated_at |
+-----+---------------------+------+---------------------+---------------------+
| 657 | 2016-11-27 15:44:34 | 1530 | 2016-11-27 15:44:34 | 2016-11-27 15:44:34 |
+-----+---------------------+------+---------------------+---------------------+
1 row in set (0.00 sec)

MySQL > select * from luxes where id = '657 ';
+-----+---------------------+------+---------------------+---------------------+
| id | recorded_at | lux | created_at | updated_at |
+-----+---------------------+------+---------------------+---------------------+
| 657 | 2016-11-27 15:44:34 | 1530 | 2016-11-27 15:44:34 | 2016-11-27 15:44:34 |
+-----+---------------------+------+---------------------+---------------------+
1 row in set (0.00 sec)

MySQL > select * from luxes where id = '657 abc';
+-----+---------------------+------+---------------------+---------------------+
| id | recorded_at | lux | created_at | updated_at |
+-----+---------------------+------+---------------------+---------------------+
| 657 | 2016-11-27 15:44:34 | 1530 | 2016-11-27 15:44:34 | 2016-11-27 15:44:34 |
+-----+---------------------+------+---------------------+---------------------+
1 row in set, 1 warning (0.00 sec)

MySQL > select * from luxes where created_at = '2016-11-27 15:44:34';
+-----+---------------------+------+---------------------+---------------------+
| id | recorded_at | lux | created_at | updated_at |
+-----+---------------------+------+---------------------+---------------------+
| 657 | 2016-11-27 15:44:34 | 1530 | 2016-11-27 15:44:34 | 2016-11-27 15:44:34 |
+-----+---------------------+------+---------------------+---------------------+
1 row in set (0.01 sec)

MySQL > select * from luxes where created_at = '2016-11-27';
Empty set (0.00 sec)

MySQL > select * from luxes where created_at = '2016-11-27 ';
Empty set (0.00 sec)

普段あんまりこういう事しないから気付いてなかったけど、Datetime型が時間の部分切り捨てられてない事から、やっぱInt型カラムに対してやった場合はこういう仕様なんかなー

と、とあるバグ対応を見て思ったので忘れないようメモ

MySQL 5.6 リファレンスマニュアル 12.3.2 比較関数と演算子