MySQL 8.0.15 ã®åå¾ã§å¤ãã£ãæåå㨠DATE åã®æ¯è¼ã«ã¤ãã¦
ã¯ããã«
ããããã°ãæè¿ãã®æã®è¨äºãæ¸ãã¦ãªããä½ãªãã¤ã³ãããããã¦ãªãäºãæãåºããä»æ¥éã«ãã¹ããã¦ãããã¾ãã¾ããã£ãé¢ç½ãæåããã£ãã®ã§ã¾ã¨ããã
ä¹
ã
ã« MySQL ã¨æ ¼éããã
åææ¡ä»¶
ãããªãã¼ãã«ãä½ã£ã¦ããã
create table hoge(t DATE); insert into hoge(t) values("2020-01-01");
mysql> desc hoge; +-------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------+------+-----+---------+-------+ | t | date | YES | | NULL | | +-------+------+------+-----+---------+-------+ 1 row in set (0.01 sec) mysql> select * from hoge; +------------+ | t | +------------+ | 2020-01-01 | +------------+ 1 row in set (0.01 sec)
ãããªãã°ãã£ãã¼ã
è¬ç¾è±¡ãåç¾ãã
8.0.15 以ä¸
mysql> select * from hoge where t > "2020"; +------------+ | t | +------------+ | 2020-01-01 | +------------+ 1 row in set, 1 warning (0.00 sec) mysql> show warnings; +---------+------+------------------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------------------+ | Warning | 1292 | Incorrect date value: '2020' for column 't' at row 1 | +---------+------+------------------------------------------------------+ 1 row in set (0.00 sec)
ãããå人çã«ã¯ï¼ï¼ã¨ããæãã ã£ãããã¾ãã¨ããããæ¾ç½®ã
8.0.16 以ä¸
mysql> select * from hoge where t > "2020"; ERROR 1525 (HY000): Incorrect DATE value: '2020'
ã¨ã©ã¼ã«ãªãã
åç
ã¾ããMySQL 8.0.15 以ä¸ã§ã¯æåå㨠DATE åãæ¯è¼ããå ´åã以ä¸ã®æé ãè¸ãã
1. æååã DATE (or DATETIME) ã«å¤æãã¦æ¯è¼ãã
2. 1.ã®å¤æãã§ããªãå ´åã¯éã« DATE ãæååã«å¤æãã¦æ¯è¼ãã
ããã MySQL 8.0.16 以ä¸ã§ã¯æ¬¡ã®ãããªæé ã«å¤æ´ãããã
1. æååã DATE (or DATETIME) ã«å¤æãã¦æ¯è¼ãã
2. 1.ã失æãã段éã§ã¨ã©ã¼ã¨ãªã
ãããMySQL 8.0.16 以ä¸ã触ã£ã¦ãã人ããããã¨æ®éã«ãã¹ããªã£ã¦æããããããªãã
MySQL 5.7.x ãã MySQL 8.0.16 以ä¸ã«ã¢ããã°ã¬ã¼ããã¦ããããããããã¨ã¾ãã³ã£ãããããã¨ãã®ä¸ãªãã
ããããã¬ãã§æååã«ãªã£ã¦ããã¿ãã㧠DATE åã®å¤ãæååã«ç´ãã¦è©ä¾¡ããã¨ãã¨åãçµæã«ãªãã
æãã¦å
é¨çã« 2020 ã¨ããæååã "2020-01-01" ã¿ããã«ä¿®æ£ããã¦ããããã§ã¯ãªãã
ã¬ã㧠DATE ãæååã¨ãã¦è©ä¾¡ããã¦ããã¿ããã
æç®
MySQL 8.0.16 ã® Release Note ã«æ¸ãã¦ãã£ãã
When comparing DATE values with constant strings, MySQL first tries to convert the string to a DATE and then to perform the comparison. When the conversion failed, MySQL executed the comparison treating the DATE as a string, which could lead to unpredictable behavior. Now in such cases, if the conversion of the string to a DATE fails, the comparison fails with ER_WRONG_VALUE. (Bug #29025656)
(DATEå¤ãå®æ°æååã¨æ¯è¼ããå ´åãMySQLã¯æåã«æååãDATEã«å¤æãã¦ããæ¯è¼ãå®è¡ãããã¨ãã¾ããå¤æã«å¤±æããå ´åãMySQLã¯DATEãæååã¨ãã¦æ±ã£ã¦æ¯è¼ãå®è¡ãããããäºæ¸¬ã§ããªãåä½ãçºçããå¯è½æ§ãããã¾ããããã®ãããªå ´åãæååã®DATEã¸ã®å¤æã«å¤±æããã¨ãER_WRONG_VALUEã§æ¯è¼ã失æããããã«ãªãã¾ããã(ãã°#29025656))
MySQL :: MySQL 8.0 Release Notes :: Changes in MySQL 8.0.16 (2019-04-25, General Availability)
ããããã Bug æ±ãããã¨ã¯æã£ããä¸å¿ãããããã¨ãããã
ã¡ãªã¿ã« 8.0.15 㧠Bug Report ãåºããã¦ãã¦ãã³ã¡ã³ããã¤ãã¦ããã
Documented fix as follows in the MySQL 8.0.16 changelog:
When comparing DATE values with constant strings, MySQL first
tries to convert the string to a DATE and then to perform the
comparison. When the conversion failed, MySQL executed the
comparison treating the DATE as a string. Now in such cases, if
the conversion of the string to a DATE fails, the comparison
fails with ER_WRONG_VALUE.Closed.
(ä¸é¨æç²)
( DATEå¤ãå®æ°æååã¨æ¯è¼ããéã«ãMySQLãæååãDATEã«å¤æãã¦ããæ¯è¼ãå®è¡ãããã¨ãããå¤æã«å¤±æããå ´åãMySQL 㯠DATE ãæååã¨ãã¦æ±ãæ¯è¼ãå®è¡ãã¦ãã¾ããããã®ãããªå ´åãæååã®DATEã¸ã®å¤æã«å¤±æããã¨ãER_WRONG_VALUEã§æ¯è¼ã«å¤±æãã¾ãã)
MySQL Bugs: #93513: Unexpected behaviour for date comparison with constant strings
ãããã«
ä»æ¥ã¯ããã«4æé溶ããã¾ããã