Skip to content

Commit a4e5902

Browse files
author
Alexander Barkov
committed
MDEV-8862 Wrong field type for MAX(COALESCE(datetime_column))
1 parent c5922c5 commit a4e5902

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

mysql-test/r/type_time.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,5 +1206,14 @@ Warning 1292 Incorrect time value: '9000000' for column 'b' at row 4
12061206
Warning 1292 Incorrect time value: '9000000' for column 'c' at row 4
12071207
DROP TABLE t1;
12081208
#
1209+
# MDEV-8862 Wrong field type for MAX(COALESCE(datetime_column))
1210+
#
1211+
CREATE TABLE t1 (a TIME);
1212+
INSERT INTO t1 VALUES ('10:10:10'),('10:20:30');
1213+
SELECT MAX(a), MAX(COALESCE(a)) FROM t1;
1214+
MAX(a) MAX(COALESCE(a))
1215+
10:20:30 10:20:30
1216+
DROP TABLE t1;
1217+
#
12091218
# End of 10.1 tests
12101219
#

mysql-test/t/type_time.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,14 @@ INSERT INTO t1 VALUES (9000000,9000000,9000000);
715715
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
716716
DROP TABLE t1;
717717

718+
--echo #
719+
--echo # MDEV-8862 Wrong field type for MAX(COALESCE(datetime_column))
720+
--echo #
721+
CREATE TABLE t1 (a TIME);
722+
INSERT INTO t1 VALUES ('10:10:10'),('10:20:30');
723+
SELECT MAX(a), MAX(COALESCE(a)) FROM t1;
724+
DROP TABLE t1;
725+
718726
--echo #
719727
--echo # End of 10.1 tests
720728
--echo #

sql/item_func.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,9 @@ bool Item_func_hybrid_result_type::get_date(MYSQL_TIME *ltime,
10891089
case STRING_RESULT:
10901090
{
10911091
if (is_temporal_type(field_type()))
1092-
return date_op(ltime, fuzzydate);
1092+
return date_op(ltime,
1093+
fuzzydate |
1094+
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
10931095
char buff[40];
10941096
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
10951097
if (!(res= str_op(&tmp)) ||

0 commit comments

Comments
 (0)