Bug #3264 FROM_DAYS() doesn't work properly in range comparison
Submitted: 22 Mar 2004 13:17 Modified: 24 Mar 2004 22:51
Reporter: jocelyn fournier (Silver Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.2 bk latest pull OS:Linux (linux)
Assigned to: Alexey Botchkov CPU Architecture:Any

[22 Mar 2004 13:17] jocelyn fournier
Description:
Hi,

When using range comparison and FROM_DAYS(), it seems the returned type is not a DATE format as expected, and thus no rows is returned in my query.

Regards,
  Jocelyn

How to repeat:
mysql> CREATE TABLE test_date (d DATETIME);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO test_date VALUES (NOW());
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO test_date VALUES (NOW());
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO test_date VALUES (NOW());
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM test_date;
+---------------------+
| d                   |
+---------------------+
| 2004-03-22 22:07:35 |
| 2004-03-22 22:07:36 |
| 2004-03-22 22:07:38 |
+---------------------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM test_date WHERE d>FROM_DAYS(TO_DAYS(NOW())) AND d<=FROM_DAYS(TO_DAYS(NOW())+1);
Empty set (0.00 sec)

=> bug, this should return all rows

mysql> SELECT * FROM test_date WHERE d>cast(FROM_DAYS(TO_DAYS(NOW())) as DATE) AND d<=cast(FROM_DAYS(TO_DAYS(NOW())+1) as DATE);
+---------------------+
| d                   |
+---------------------+
| 2004-03-22 22:07:35 |
| 2004-03-22 22:07:36 |
| 2004-03-22 22:07:38 |
+---------------------+
3 rows in set (0.00 sec)

=> ok if I explicitly cast FROM_DAYS result in DATE format
[22 Mar 2004 15:01] Dean Ellis
Verified against 4.1.2.  Thank you.
[23 Mar 2004 7:45] Alexey Botchkov
bk commit - 4.1 tree (hf:1.1713)
[24 Mar 2004 22:51] Alexey Botchkov
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