Bug #33772 | Monthname (string) comparison with Month (integer) succeeds where it shouldn't | ||
---|---|---|---|
Submitted: | 9 Jan 2008 14:58 | Modified: | 10 Jan 2008 12:25 |
Reporter: | Vares Pierre-Olivier | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Data Types | Severity: | S3 (Non-critical) |
Version: | 5.0-bk, 5.1-bk | OS: | Any |
Assigned to: | Assigned Account | CPU Architecture: | Any |
Tags: | comparison, month, monthname |
[9 Jan 2008 14:58]
Vares Pierre-Olivier
[9 Jan 2008 15:16]
Paul DuBois
The comparison seems to succeed because MONTHNAME(NOW()) becomes 1 (not 0) when converted to numeric form. mysql> SELECT NOW(), MONTHNAME(NOW()), 'January'; +---------------------+------------------+---------+ | NOW() | MONTHNAME(NOW()) | January | +---------------------+------------------+---------+ | 2008-01-09 09:14:11 | January | January | +---------------------+------------------+---------+ 1 row in set (0.00 sec) mysql> SELECT MONTHNAME(NOW())+0, 'January'+0; +--------------------+-------------+ | MONTHNAME(NOW())+0 | 'January'+0 | +--------------------+-------------+ | 1 | 0 | +--------------------+-------------+ 1 row in set, 1 warning (0.15 sec) mysql> SHOW WARNINGS; +---------+------+---------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'January' | +---------+------+---------------------------------------------+ 1 row in set (0.47 sec) I would have expected MONTHNAME(NOW())+0 to be 0, not 1...
[9 Jan 2008 15:41]
Vares Pierre-Olivier
The same arises with December : SELECT MONTHNAME('2007-12-25'), MONTH('2007-12-25') FROM (SELECT 'x' dummy) dummytable WHERE MONTHNAME('2007-12-25') = MONTH('2007-12-25') +-------------------------+---------------------+ | MONTHNAME('2007-12-25') | MONTH('2007-12-25') | +-------------------------+---------------------+ | December | 12 | +-------------------------+---------------------+ A "SHOW WARNINGS" result in an "empty set" in both case (with now() and with '2007-12-25') The implicit conversion I was talking about is clearly put in evidence here : SELECT MONTHNAME('2007-12-25')+0, MONTH('2007-12-25')+0 FROM (SELECT 'x' dummy) dummytable WHERE MONTHNAME('2007-12-25') = MONTH('2007-12-25') +---------------------------+-----------------------+ | MONTHNAME('2007-12-25')+0 | MONTH('2007-12-25')+0 | +---------------------------+-----------------------+ | 12 | 12 | +---------------------------+-----------------------+
[10 Jan 2008 12:25]
Susanne Ebrecht
Verified as described with bk trees from 5.0 and 5.1.