[MDEV-5692] Difference between DATE(int_expression) and DATE(int_field) Created: 2014-02-17  Updated: 2022-11-01  Resolved: 2022-11-01

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 10.0.8
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None


 Description   

This SQL script returns NULL with a warning:

mysql> drop table if exists t1; create table t1 (a int); insert into t1 values (0); select date(a)from t1;
Query OK, 0 rows affected (0.03 sec)
 
Query OK, 0 rows affected (0.15 sec)
 
Query OK, 1 row affected (0.00 sec)
 
+---------+
| date(a) |
+---------+
| NULL    |
+---------+
1 row in set, 1 warning (1.37 sec)
 
mysql> show warnings;
+---------+------+-------------------------------+
| Level   | Code | Message                       |
+---------+------+-------------------------------+
| Warning | 1292 | Incorrect datetime value: '0' |
+---------+------+-------------------------------+
1 row in set (0.00 sec)

At the same time, this query returns '0000-00-00' without warnings.

mysql> select date(0);
+------------+
| date(0)    |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)

One of the either should be fixed for equal results.

The same problems is observed when converting 0 to DATETIME:

drop table if exists t1;
create table t1 (a int);
insert into t1 values (0);
select timestamp(a),timestamp(0) from t1;
+--------------+---------------------+
| timestamp(a) | timestamp(0)        |
+--------------+---------------------+
| NULL         | 0000-00-00 00:00:00 |
+--------------+---------------------+
1 row in set, 1 warning (0.00 sec)

The same problem is observed with the DECIMAL data type:

drop table if exists t1;
create table t1 (a decimal);
insert into t1 values (0);
select timestamp(a),timestamp(0.0) from t1;
+--------------+-----------------------+
| timestamp(a) | timestamp(0.0)        |
+--------------+-----------------------+
| NULL         | 0000-00-00 00:00:00.0 |
+--------------+-----------------------+



 Comments   
Comment by Sergei Golubchik [ 2022-11-01 ]

fixed at some point before 10.3.37

Generated at Thu Feb 08 07:06:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.