Commit a4848e97 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9972 Least function retuns date in date time format

parent b31976f5
...@@ -442,6 +442,7 @@ select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1; ...@@ -442,6 +442,7 @@ select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
drop table t1; drop table t1;
# #
# MDEV-9521 Least function returns 0000-00-00 for null date columns instead of null # MDEV-9521 Least function returns 0000-00-00 for null date columns instead of null
# MDEV-9972 Least function retuns date in date time format
# #
CREATE TABLE t1 ( CREATE TABLE t1 (
id BIGINT NOT NULL, id BIGINT NOT NULL,
...@@ -465,9 +466,9 @@ LEAST(IFNULL(t2.date_fin, IFNULL(t1.date_fin, NULL)), ...@@ -465,9 +466,9 @@ LEAST(IFNULL(t2.date_fin, IFNULL(t1.date_fin, NULL)),
IFNULL(t1.date_fin, IFNULL(t2.date_fin, NULL))) AS date_fin IFNULL(t1.date_fin, IFNULL(t2.date_fin, NULL))) AS date_fin
FROM t1 LEFT JOIN t2 ON (t1.id=t2.id); FROM t1 LEFT JOIN t2 ON (t1.id=t2.id);
id date_debut date_fin id date_debut date_fin
1 2016-01-01 2016-01-31 00:00:00 1 2016-01-01 2016-01-31
2 2016-02-01 2016-01-28 00:00:00 2 2016-02-01 2016-01-28
3 2016-03-01 2016-03-31 00:00:00 3 2016-03-01 2016-03-31
4 2016-04-01 NULL 4 2016-04-01 NULL
DROP TABLE t1,t2; DROP TABLE t1,t2;
SELECT SELECT
......
...@@ -388,6 +388,7 @@ drop table t1; ...@@ -388,6 +388,7 @@ drop table t1;
--echo # --echo #
--echo # MDEV-9521 Least function returns 0000-00-00 for null date columns instead of null --echo # MDEV-9521 Least function returns 0000-00-00 for null date columns instead of null
--echo # MDEV-9972 Least function retuns date in date time format
--echo # --echo #
CREATE TABLE t1 ( CREATE TABLE t1 (
id BIGINT NOT NULL, id BIGINT NOT NULL,
......
...@@ -2939,12 +2939,13 @@ bool Item_func_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) ...@@ -2939,12 +2939,13 @@ bool Item_func_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
} }
unpack_time(min_max, ltime); unpack_time(min_max, ltime);
if (compare_as_dates->field_type() == MYSQL_TYPE_DATE) enum_field_types ftype= compare_as_dates->field_type();
if (ftype == MYSQL_TYPE_DATE || ftype == MYSQL_TYPE_NEWDATE)
{ {
ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->time_type= MYSQL_TIMESTAMP_DATE;
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0; ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
} }
else if (compare_as_dates->field_type() == MYSQL_TYPE_TIME) else if (ftype == MYSQL_TYPE_TIME)
{ {
ltime->time_type= MYSQL_TIMESTAMP_TIME; ltime->time_type= MYSQL_TIMESTAMP_TIME;
ltime->hour+= (ltime->month * 32 + ltime->day) * 24; ltime->hour+= (ltime->month * 32 + ltime->day) * 24;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment