Bug #3115 CAST AS DATE with malformed string returns NULL but IS NULL is false.
Submitted: 9 Mar 2004 7:50 Modified: 9 Mar 2004 13:19
Reporter: Per-Erik Martin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1 OS:Any (Any)
Assigned to: Jani Tolonen CPU Architecture:Any

[9 Mar 2004 7:50] Per-Erik Martin
Description:
CAST('20030x12' AS DATE) returns NULL when used in a SELECT or set
to a user defined variable, but testing with IS NULL returns false (0).

(Note: Maybe the SQL-99/2003-ish way would be to return an error?)

How to repeat:
mysql> select cast('20030312' as date);
+--------------------------+
| cast('20030312' as date) |
+--------------------------+
| 2003-03-12               |
+--------------------------+
1 row in set (0.00 sec)

mysql> select cast('20030x12' as date);
+--------------------------+
| cast('20030x12' as date) |
+--------------------------+
| NULL                     |
+--------------------------+
1 row in set (0.00 sec)

mysql> select cast('20030x12' as date) is null;
+----------------------------------+
| cast('20030x12' as date) is null |
+----------------------------------+
|                                0 |
+----------------------------------+
1 row in set (0.00 sec)

mysql> set @x = cast('20030x12' as date);
Query OK, 0 rows affected (0.00 sec)

mysql> select @x, @x is null;
+------+------------+
| @x   | @x is null |
+------+------------+
| NULL |          1 |
+------+------------+
1 row in set (0.00 sec)
[9 Mar 2004 8:31] Dean Ellis
Verified against 4.1.2.

SELECT CAST('20030x12' AS DATE) <=> NULL;  reports true.
[9 Mar 2004 13:19] Jani Tolonen
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Fix will be in 4.1.2.
bk ChangeSet 1.1773