[MDEV-8660] TIME(int_zerofill_column) returns a wrong result Created: 2015-08-21  Updated: 2015-09-23  Resolved: 2015-09-23

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 10.1.8

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: upstream-not-affected

Issue Links:
Relates
relates to MDEV-8658 DATE(zerofill_column) and DATE(COALES... Closed
Sprint: 10.1.8-3

 Description   

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a BIGINT(15), b BIGINT(15) ZEROFILL);
INSERT INTO t1 VALUES (9,9);
SELECT TIME(a),TIME(b) FROM t1;
SHOW WARNINGS;

returns

+----------+----------+
| TIME(a)  | TIME(b)  |
+----------+----------+
| 00:00:09 | 00:00:00 |
+----------+----------+
1 row in set, 1 warning (0.00 sec)

with a warning:

+---------+------+---------------------------------------------------+
| Level   | Code | Message                                           |
+---------+------+---------------------------------------------------+
| Warning | 1292 | Truncated incorrect time value: '000000000000009' |
+---------+------+---------------------------------------------------+

The expected behavior is to return '00:00:09' for both columns, with no warnings.

The same problem is repeatable with the DECIMAL data type:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(15,0), b DECIMAL(15,0) ZEROFILL);
INSERT INTO t1 VALUES (9,9);
SELECT TIME(a),TIME(b) FROM t1;
SHOW WARNINGS;

More related problems:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a BIGINT);
INSERT INTO t1 VALUES (-9223372036854775808);
SELECT CAST(a AS TIME), CAST(-9223372036854775808 AS TIME) FROM t1; 

returns:

+-----------------+------------------------------------+
| CAST(a AS TIME) | CAST(-9223372036854775808 AS TIME) |
+-----------------+------------------------------------+
| NULL            | -838:59:59                         |
+-----------------+------------------------------------+

Notice, a field and a literal produce different results for the same value.



 Comments   
Comment by Alexander Barkov [ 2015-09-23 ]

Not repeatable in MySQL-5.7.8

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