Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
accf9b56
Commit
accf9b56
authored
Oct 01, 2015
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-5694 GREATEST(date, time) returns a wrong data type
parent
a84fae27
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
837 additions
and
38 deletions
+837
-38
mysql-test/r/func_hybrid_type.result
mysql-test/r/func_hybrid_type.result
+742
-0
mysql-test/r/func_time.result
mysql-test/r/func_time.result
+13
-19
mysql-test/t/func_hybrid_type.test
mysql-test/t/func_hybrid_type.test
+54
-0
mysql-test/t/func_time.test
mysql-test/t/func_time.test
+3
-1
sql/item_func.cc
sql/item_func.cc
+23
-14
sql/item_func.h
sql/item_func.h
+2
-4
No files found.
mysql-test/r/func_hybrid_type.result
View file @
accf9b56
...
...
@@ -2096,6 +2096,718 @@ t2 CREATE TABLE `t2` (
DROP TABLE t2;
DROP TABLE t1;
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 01:02:03');
CREATE TABLE t1 (a DATE, b TIME);
INSERT INTO t1 VALUES ('2010-01-01','10:20:30');
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 a ___________a 10 10 10 Y 128 0 63
def case_______a 10 10 10 Y 128 0 63
def case_____a_a 10 10 10 Y 128 0 63
def coalesce___a 10 10 10 Y 128 0 63
def coalesce_a_a 10 10 10 Y 128 0 63
def if_______a_a 10 10 10 Y 128 0 63
def ifnull___a_a 10 10 10 Y 128 0 63
def least____a_a 10 10 10 Y 128 0 63
def greatest_a_a 10 10 10 Y 128 0 63
def test t1 t1 b ___________b 11 10 8 Y 128 0 63
def case_______b 11 10 8 Y 128 0 63
def case_____b_b 11 10 8 Y 128 0 63
def coalesce___b 11 10 8 Y 128 0 63
def coalesce_b_b 11 10 8 Y 128 0 63
def if_______b_b 11 10 8 Y 128 0 63
def ifnull___b_b 11 10 8 Y 128 0 63
def least____b_b 11 10 8 Y 128 0 63
def greatest_b_b 11 10 8 Y 128 0 63
___________a 2010-01-01
case_______a 2010-01-01
case_____a_a 2010-01-01
coalesce___a 2010-01-01
coalesce_a_a 2010-01-01
if_______a_a 2010-01-01
ifnull___a_a 2010-01-01
least____a_a 2010-01-01
greatest_a_a 2010-01-01
___________b 10:20:30
case_______b 10:20:30
case_____b_b 10:20:30
coalesce___b 10:20:30
coalesce_b_b 10:20:30
if_______b_b 10:20:30
ifnull___b_b 10:20:30
least____b_b 10:20:30
greatest_b_b 10:20:30
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def case_____a_b 12 19 19 Y 128 0 63
def case_____b_a 12 19 19 Y 128 0 63
def coalesce_a_b 12 19 19 Y 128 0 63
def coalesce_b_a 12 19 19 Y 128 0 63
def if_______a_b 12 10 19 Y 128 0 63
def if_______b_a 12 10 19 Y 128 0 63
def ifnull___a_b 12 10 19 Y 128 0 63
def ifnull___b_a 12 10 19 Y 128 0 63
def least____a_b 12 10 19 Y 128 0 63
def least____b_a 12 10 19 Y 128 0 63
def greatest_a_b 12 10 19 Y 128 0 63
def greatest_b_a 12 10 19 Y 128 0 63
case_____a_b 2010-01-01 00:00:00
case_____b_a 2001-01-01 10:20:30
coalesce_a_b 2010-01-01 00:00:00
coalesce_b_a 2001-01-01 10:20:30
if_______a_b 2001-01-01 10:20:30
if_______b_a 2010-01-01 00:00:00
ifnull___a_b 2010-01-01 00:00:00
ifnull___b_a 2001-01-01 10:20:30
least____a_b 2001-01-01 10:20:30
least____b_a 2001-01-01 10:20:30
greatest_a_b 2010-01-01 00:00:00
greatest_b_a 2010-01-01 00:00:00
CREATE TABLE t2 AS
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`___________a` date DEFAULT NULL,
`case_______a` date DEFAULT NULL,
`case_____a_a` date DEFAULT NULL,
`coalesce___a` date DEFAULT NULL,
`coalesce_a_a` date DEFAULT NULL,
`if_______a_a` date DEFAULT NULL,
`ifnull___a_a` date DEFAULT NULL,
`least____a_a` date DEFAULT NULL,
`greatest_a_a` date DEFAULT NULL,
`___________b` time DEFAULT NULL,
`case_______b` time DEFAULT NULL,
`case_____b_b` time DEFAULT NULL,
`coalesce___b` time DEFAULT NULL,
`coalesce_b_b` time DEFAULT NULL,
`if_______b_b` time DEFAULT NULL,
`ifnull___b_b` time DEFAULT NULL,
`least____b_b` time DEFAULT NULL,
`greatest_b_b` time DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
CREATE TABLE t2 AS
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`case_____a_b` datetime DEFAULT NULL,
`case_____b_a` datetime DEFAULT NULL,
`coalesce_a_b` datetime DEFAULT NULL,
`coalesce_b_a` datetime DEFAULT NULL,
`if_______a_b` datetime DEFAULT NULL,
`if_______b_a` datetime DEFAULT NULL,
`ifnull___a_b` datetime DEFAULT NULL,
`ifnull___b_a` datetime DEFAULT NULL,
`least____a_b` datetime DEFAULT NULL,
`least____b_a` datetime DEFAULT NULL,
`greatest_a_b` datetime DEFAULT NULL,
`greatest_b_a` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
DROP TABLE t1;
SET timestamp=DEFAULT;
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 01:02:03');
CREATE TABLE t1 (a TIMESTAMP, b TIME);
INSERT INTO t1 VALUES ('2010-01-01 00:00:00','10:20:30');
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 a ___________a 7 19 19 N 9377 0 63
def case_______a 7 19 19 Y 128 0 63
def case_____a_a 7 19 19 N 129 0 63
def coalesce___a 7 19 19 N 129 0 63
def coalesce_a_a 7 19 19 N 129 0 63
def if_______a_a 7 19 19 N 129 0 63
def ifnull___a_a 7 19 19 N 129 0 63
def least____a_a 7 19 19 N 161 0 63
def greatest_a_a 7 19 19 N 161 0 63
def test t1 t1 b ___________b 11 10 8 Y 128 0 63
def case_______b 11 10 8 Y 128 0 63
def case_____b_b 11 10 8 Y 128 0 63
def coalesce___b 11 10 8 Y 128 0 63
def coalesce_b_b 11 10 8 Y 128 0 63
def if_______b_b 11 10 8 Y 128 0 63
def ifnull___b_b 11 10 8 Y 128 0 63
def least____b_b 11 10 8 Y 128 0 63
def greatest_b_b 11 10 8 Y 128 0 63
___________a 2010-01-01 00:00:00
case_______a 2010-01-01 00:00:00
case_____a_a 2010-01-01 00:00:00
coalesce___a 2010-01-01 00:00:00
coalesce_a_a 2010-01-01 00:00:00
if_______a_a 2010-01-01 00:00:00
ifnull___a_a 2010-01-01 00:00:00
least____a_a 2010-01-01 00:00:00
greatest_a_a 2010-01-01 00:00:00
___________b 10:20:30
case_______b 10:20:30
case_____b_b 10:20:30
coalesce___b 10:20:30
coalesce_b_b 10:20:30
if_______b_b 10:20:30
ifnull___b_b 10:20:30
least____b_b 10:20:30
greatest_b_b 10:20:30
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def case_____a_b 12 19 19 Y 128 0 63
def case_____b_a 12 19 19 Y 128 0 63
def coalesce_a_b 12 19 19 Y 128 0 63
def coalesce_b_a 12 19 19 Y 128 0 63
def if_______a_b 12 19 19 Y 128 0 63
def if_______b_a 12 19 19 Y 128 0 63
def ifnull___a_b 12 19 19 Y 128 0 63
def ifnull___b_a 12 19 19 N 129 0 63
def least____a_b 12 19 19 Y 128 0 63
def least____b_a 12 19 19 Y 128 0 63
def greatest_a_b 12 19 19 Y 128 0 63
def greatest_b_a 12 19 19 Y 128 0 63
case_____a_b 2010-01-01 00:00:00
case_____b_a 2001-01-01 10:20:30
coalesce_a_b 2010-01-01 00:00:00
coalesce_b_a 2001-01-01 10:20:30
if_______a_b 2001-01-01 10:20:30
if_______b_a 2010-01-01 00:00:00
ifnull___a_b 2010-01-01 00:00:00
ifnull___b_a 2001-01-01 10:20:30
least____a_b 2001-01-01 10:20:30
least____b_a 2001-01-01 10:20:30
greatest_a_b 2010-01-01 00:00:00
greatest_b_a 2010-01-01 00:00:00
CREATE TABLE t2 AS
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`___________a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`case_______a` timestamp NULL DEFAULT NULL,
`case_____a_a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`coalesce___a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`coalesce_a_a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`if_______a_a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`ifnull___a_a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`least____a_a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`greatest_a_a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`___________b` time DEFAULT NULL,
`case_______b` time DEFAULT NULL,
`case_____b_b` time DEFAULT NULL,
`coalesce___b` time DEFAULT NULL,
`coalesce_b_b` time DEFAULT NULL,
`if_______b_b` time DEFAULT NULL,
`ifnull___b_b` time DEFAULT NULL,
`least____b_b` time DEFAULT NULL,
`greatest_b_b` time DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
CREATE TABLE t2 AS
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`case_____a_b` datetime DEFAULT NULL,
`case_____b_a` datetime DEFAULT NULL,
`coalesce_a_b` datetime DEFAULT NULL,
`coalesce_b_a` datetime DEFAULT NULL,
`if_______a_b` datetime DEFAULT NULL,
`if_______b_a` datetime DEFAULT NULL,
`ifnull___a_b` datetime DEFAULT NULL,
`ifnull___b_a` datetime NOT NULL,
`least____a_b` datetime DEFAULT NULL,
`least____b_a` datetime DEFAULT NULL,
`greatest_a_b` datetime DEFAULT NULL,
`greatest_b_a` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
DROP TABLE t1;
SET timestamp=DEFAULT;
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 01:02:03');
CREATE TABLE t1 (a DATETIME, b TIME);
INSERT INTO t1 VALUES ('2010-01-01 00:00:00','10:20:30');
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 a ___________a 12 19 19 Y 128 0 63
def case_______a 12 19 19 Y 128 0 63
def case_____a_a 12 19 19 Y 128 0 63
def coalesce___a 12 19 19 Y 128 0 63
def coalesce_a_a 12 19 19 Y 128 0 63
def if_______a_a 12 19 19 Y 128 0 63
def ifnull___a_a 12 19 19 Y 128 0 63
def least____a_a 12 19 19 Y 128 0 63
def greatest_a_a 12 19 19 Y 128 0 63
def test t1 t1 b ___________b 11 10 8 Y 128 0 63
def case_______b 11 10 8 Y 128 0 63
def case_____b_b 11 10 8 Y 128 0 63
def coalesce___b 11 10 8 Y 128 0 63
def coalesce_b_b 11 10 8 Y 128 0 63
def if_______b_b 11 10 8 Y 128 0 63
def ifnull___b_b 11 10 8 Y 128 0 63
def least____b_b 11 10 8 Y 128 0 63
def greatest_b_b 11 10 8 Y 128 0 63
___________a 2010-01-01 00:00:00
case_______a 2010-01-01 00:00:00
case_____a_a 2010-01-01 00:00:00
coalesce___a 2010-01-01 00:00:00
coalesce_a_a 2010-01-01 00:00:00
if_______a_a 2010-01-01 00:00:00
ifnull___a_a 2010-01-01 00:00:00
least____a_a 2010-01-01 00:00:00
greatest_a_a 2010-01-01 00:00:00
___________b 10:20:30
case_______b 10:20:30
case_____b_b 10:20:30
coalesce___b 10:20:30
coalesce_b_b 10:20:30
if_______b_b 10:20:30
ifnull___b_b 10:20:30
least____b_b 10:20:30
greatest_b_b 10:20:30
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def case_____a_b 12 19 19 Y 128 0 63
def case_____b_a 12 19 19 Y 128 0 63
def coalesce_a_b 12 19 19 Y 128 0 63
def coalesce_b_a 12 19 19 Y 128 0 63
def if_______a_b 12 19 19 Y 128 0 63
def if_______b_a 12 19 19 Y 128 0 63
def ifnull___a_b 12 19 19 Y 128 0 63
def ifnull___b_a 12 19 19 Y 128 0 63
def least____a_b 12 19 19 Y 128 0 63
def least____b_a 12 19 19 Y 128 0 63
def greatest_a_b 12 19 19 Y 128 0 63
def greatest_b_a 12 19 19 Y 128 0 63
case_____a_b 2010-01-01 00:00:00
case_____b_a 2001-01-01 10:20:30
coalesce_a_b 2010-01-01 00:00:00
coalesce_b_a 2001-01-01 10:20:30
if_______a_b 2001-01-01 10:20:30
if_______b_a 2010-01-01 00:00:00
ifnull___a_b 2010-01-01 00:00:00
ifnull___b_a 2001-01-01 10:20:30
least____a_b 2001-01-01 10:20:30
least____b_a 2001-01-01 10:20:30
greatest_a_b 2010-01-01 00:00:00
greatest_b_a 2010-01-01 00:00:00
CREATE TABLE t2 AS
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`___________a` datetime DEFAULT NULL,
`case_______a` datetime DEFAULT NULL,
`case_____a_a` datetime DEFAULT NULL,
`coalesce___a` datetime DEFAULT NULL,
`coalesce_a_a` datetime DEFAULT NULL,
`if_______a_a` datetime DEFAULT NULL,
`ifnull___a_a` datetime DEFAULT NULL,
`least____a_a` datetime DEFAULT NULL,
`greatest_a_a` datetime DEFAULT NULL,
`___________b` time DEFAULT NULL,
`case_______b` time DEFAULT NULL,
`case_____b_b` time DEFAULT NULL,
`coalesce___b` time DEFAULT NULL,
`coalesce_b_b` time DEFAULT NULL,
`if_______b_b` time DEFAULT NULL,
`ifnull___b_b` time DEFAULT NULL,
`least____b_b` time DEFAULT NULL,
`greatest_b_b` time DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
CREATE TABLE t2 AS
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`case_____a_b` datetime DEFAULT NULL,
`case_____b_a` datetime DEFAULT NULL,
`coalesce_a_b` datetime DEFAULT NULL,
`coalesce_b_a` datetime DEFAULT NULL,
`if_______a_b` datetime DEFAULT NULL,
`if_______b_a` datetime DEFAULT NULL,
`ifnull___a_b` datetime DEFAULT NULL,
`ifnull___b_a` datetime DEFAULT NULL,
`least____a_b` datetime DEFAULT NULL,
`least____b_a` datetime DEFAULT NULL,
`greatest_a_b` datetime DEFAULT NULL,
`greatest_b_a` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
DROP TABLE t1;
SET timestamp=DEFAULT;
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 01:02:03');
CREATE TABLE t1 (a DATETIME, b DATE);
INSERT INTO t1 VALUES ('2010-01-01 10:20:30','2001-01-02');
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 a ___________a 12 19 19 Y 128 0 63
def case_______a 12 19 19 Y 128 0 63
def case_____a_a 12 19 19 Y 128 0 63
def coalesce___a 12 19 19 Y 128 0 63
def coalesce_a_a 12 19 19 Y 128 0 63
def if_______a_a 12 19 19 Y 128 0 63
def ifnull___a_a 12 19 19 Y 128 0 63
def least____a_a 12 19 19 Y 128 0 63
def greatest_a_a 12 19 19 Y 128 0 63
def test t1 t1 b ___________b 10 10 10 Y 128 0 63
def case_______b 10 10 10 Y 128 0 63
def case_____b_b 10 10 10 Y 128 0 63
def coalesce___b 10 10 10 Y 128 0 63
def coalesce_b_b 10 10 10 Y 128 0 63
def if_______b_b 10 10 10 Y 128 0 63
def ifnull___b_b 10 10 10 Y 128 0 63
def least____b_b 10 10 10 Y 128 0 63
def greatest_b_b 10 10 10 Y 128 0 63
___________a 2010-01-01 10:20:30
case_______a 2010-01-01 10:20:30
case_____a_a 2010-01-01 10:20:30
coalesce___a 2010-01-01 10:20:30
coalesce_a_a 2010-01-01 10:20:30
if_______a_a 2010-01-01 10:20:30
ifnull___a_a 2010-01-01 10:20:30
least____a_a 2010-01-01 10:20:30
greatest_a_a 2010-01-01 10:20:30
___________b 2001-01-02
case_______b 2001-01-02
case_____b_b 2001-01-02
coalesce___b 2001-01-02
coalesce_b_b 2001-01-02
if_______b_b 2001-01-02
ifnull___b_b 2001-01-02
least____b_b 2001-01-02
greatest_b_b 2001-01-02
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def case_____a_b 12 19 19 Y 128 0 63
def case_____b_a 12 19 19 Y 128 0 63
def coalesce_a_b 12 19 19 Y 128 0 63
def coalesce_b_a 12 19 19 Y 128 0 63
def if_______a_b 12 19 19 Y 128 0 63
def if_______b_a 12 19 19 Y 128 0 63
def ifnull___a_b 12 19 19 Y 128 0 63
def ifnull___b_a 12 19 19 Y 128 0 63
def least____a_b 12 19 19 Y 128 0 63
def least____b_a 12 19 19 Y 128 0 63
def greatest_a_b 12 19 19 Y 128 0 63
def greatest_b_a 12 19 19 Y 128 0 63
case_____a_b 2010-01-01 10:20:30
case_____b_a 2001-01-02 00:00:00
coalesce_a_b 2010-01-01 10:20:30
coalesce_b_a 2001-01-02 00:00:00
if_______a_b 2001-01-02 00:00:00
if_______b_a 2010-01-01 10:20:30
ifnull___a_b 2010-01-01 10:20:30
ifnull___b_a 2001-01-02 00:00:00
least____a_b 2001-01-02 00:00:00
least____b_a 2001-01-02 00:00:00
greatest_a_b 2010-01-01 10:20:30
greatest_b_a 2010-01-01 10:20:30
CREATE TABLE t2 AS
SELECT
a AS ___________a,
CASE WHEN a IS NOT NULL THEN a END AS case_______a,
CASE WHEN a IS NOT NULL THEN a ELSE a END AS case_____a_a,
COALESCE(a) AS coalesce___a,
COALESCE(a, a) AS coalesce_a_a,
IF(a IS NULL, a, a) AS if_______a_a,
IFNULL(a, a) AS ifnull___a_a,
LEAST(a, a) AS least____a_a,
GREATEST(a, a) AS greatest_a_a,
b AS ___________b,
CASE WHEN a IS NOT NULL THEN b END AS case_______b,
CASE WHEN a IS NOT NULL THEN b ELSE b END AS case_____b_b,
COALESCE(b) AS coalesce___b,
COALESCE(b, b) AS coalesce_b_b,
IF(a IS NULL, b, b) AS if_______b_b,
IFNULL(b, b) AS ifnull___b_b,
LEAST(b, b) AS least____b_b,
GREATEST(b, b) AS greatest_b_b
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`___________a` datetime DEFAULT NULL,
`case_______a` datetime DEFAULT NULL,
`case_____a_a` datetime DEFAULT NULL,
`coalesce___a` datetime DEFAULT NULL,
`coalesce_a_a` datetime DEFAULT NULL,
`if_______a_a` datetime DEFAULT NULL,
`ifnull___a_a` datetime DEFAULT NULL,
`least____a_a` datetime DEFAULT NULL,
`greatest_a_a` datetime DEFAULT NULL,
`___________b` date DEFAULT NULL,
`case_______b` date DEFAULT NULL,
`case_____b_b` date DEFAULT NULL,
`coalesce___b` date DEFAULT NULL,
`coalesce_b_b` date DEFAULT NULL,
`if_______b_b` date DEFAULT NULL,
`ifnull___b_b` date DEFAULT NULL,
`least____b_b` date DEFAULT NULL,
`greatest_b_b` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
CREATE TABLE t2 AS
SELECT
CASE WHEN a IS NOT NULL THEN a ELSE b END AS case_____a_b,
CASE WHEN a IS NOT NULL THEN b ELSE a END AS case_____b_a,
COALESCE(a, b) AS coalesce_a_b,
COALESCE(b, a) AS coalesce_b_a,
IF(a IS NULL, a, b) AS if_______a_b,
IF(a IS NULL, b, a) AS if_______b_a,
IFNULL(a, b) AS ifnull___a_b,
IFNULL(b, a) AS ifnull___b_a,
LEAST(a, b) AS least____a_b,
LEAST(b, a) AS least____b_a,
GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`case_____a_b` datetime DEFAULT NULL,
`case_____b_a` datetime DEFAULT NULL,
`coalesce_a_b` datetime DEFAULT NULL,
`coalesce_b_a` datetime DEFAULT NULL,
`if_______a_b` datetime DEFAULT NULL,
`if_______b_a` datetime DEFAULT NULL,
`ifnull___a_b` datetime DEFAULT NULL,
`ifnull___b_a` datetime DEFAULT NULL,
`least____a_b` datetime DEFAULT NULL,
`least____b_a` datetime DEFAULT NULL,
`greatest_a_b` datetime DEFAULT NULL,
`greatest_b_a` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# MDEV-8873 Wrong field type or metadata for LEAST(int_column,string_column)
#
CREATE TABLE t1 (a INT, b VARCHAR(10));
...
...
@@ -2317,5 +3029,35 @@ a
13836376518955650385
DROP TABLE t1;
#
# MDEV-5694 GREATEST(date, time) returns a wrong data type
#
SET timestamp=UNIX_TIMESTAMP('2010-01-01 01:02:03');
SELECT GREATEST(CURRENT_TIME, CURRENT_DATE), COALESCE(CURRENT_TIME, CURRENT_DATE);
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def GREATEST(CURRENT_TIME, CURRENT_DATE) 12 10 19 N 129 0 63
def COALESCE(CURRENT_TIME, CURRENT_DATE) 12 19 19 N 129 0 63
GREATEST(CURRENT_TIME, CURRENT_DATE) COALESCE(CURRENT_TIME, CURRENT_DATE)
2010-01-01 01:02:03 2010-01-01 01:02:03
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES ('2010-01-01 10:20:30');
SELECT GREATEST(a,a) FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def GREATEST(a,a) 7 19 19 N 161 0 63
GREATEST(a,a)
2010-01-01 10:20:30
DROP TABLE t1;
CREATE TABLE t1 (a TIMESTAMP, b DATETIME);
CREATE TABLE t2 AS SELECT LEAST(a,a),LEAST(b,b),LEAST(a,b) FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`LEAST(a,a)` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`LEAST(b,b)` datetime DEFAULT NULL,
`LEAST(a,b)` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# End of 10.1 tests
#
mysql-test/r/func_time.result
View file @
accf9b56
...
...
@@ -1919,16 +1919,19 @@ drop table t1;
SET timestamp=UNIX_TIMESTAMP('2014-06-01 10:20:30');
select greatest(cast("0-0-0" as date), cast("10:20:05" as time));
greatest(cast("0-0-0" as date), cast("10:20:05" as time))
2014-06-01
2014-06-01
10:20:05
select greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '0000-00-00';
greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '0000-00-00'
0
select greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '2014-06-01';
greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '2014-06-01'
0
select greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '2014-06-01 10:20:05';
greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '2014-06-01 10:20:05'
1
select cast(greatest(cast("0-0-0" as date), cast("10:20:05" as time)) as datetime(6));
cast(greatest(cast("0-0-0" as date), cast("10:20:05" as time)) as datetime(6))
2014-06-01
00:00:00
.000000
2014-06-01
10:20:05
.000000
SET timestamp=DEFAULT;
select microsecond('12:00:00.123456'), microsecond('2009-12-31 23:59:59.000010');
microsecond('12:00:00.123456') microsecond('2009-12-31 23:59:59.000010')
...
...
@@ -2563,18 +2566,12 @@ CREATE TABLE t1 (t TIME);
INSERT INTO t1 VALUES ('03:22:30'),('18:30:05');
SELECT CONVERT_TZ(GREATEST(t, CURRENT_DATE()), '+02:00', '+10:00') FROM t1;
CONVERT_TZ(GREATEST(t, CURRENT_DATE()), '+02:00', '+10:00')
2014-02-26 06:59:59
2014-02-26 06:59:59
Warnings:
Warning 1292 Truncated incorrect time value: '1296:00:00'
Warning 1292 Truncated incorrect time value: '1296:00:00'
2014-01-22 11:22:30
2014-01-23 02:30:05
SELECT GREATEST(t, CURRENT_DATE()) FROM t1;
GREATEST(t, CURRENT_DATE())
838:59:59
838:59:59
Warnings:
Warning 1292 Truncated incorrect time value: '1296:00:00'
Warning 1292 Truncated incorrect time value: '1296:00:00'
2014-01-22 03:22:30
2014-01-22 18:30:05
DROP TABLE t1;
SET TIMESTAMP=DEFAULT;
#
...
...
@@ -2695,18 +2692,15 @@ SET timestamp=DEFAULT;
#
# MDEV-5750 Assertion `ltime->year == 0' fails on a query with EXTRACT DAY_MINUTE and TIME column
#
SET timestamp=UNIX_TIMESTAMP('2010-01-01 00:00:00');
CREATE TABLE t1 ( d DATE, t TIME );
INSERT INTO t1 VALUES ('2008-12-05','22:34:09'),('2005-03-27','14:26:02');
SELECT EXTRACT(DAY_MINUTE FROM GREATEST(t,d)), GREATEST(t,d) FROM t1;
EXTRACT(DAY_MINUTE FROM GREATEST(t,d)) GREATEST(t,d)
342259 838:59:59
342259 838:59:59
Warnings:
Warning 1292 Truncated incorrect time value: '9336:00:00'
Warning 1292 Truncated incorrect time value: '9336:00:00'
Warning 1292 Truncated incorrect time value: '2952:00:00'
Warning 1292 Truncated incorrect time value: '2952:00:00'
12234 2010-01-01 22:34:09
11426 2010-01-01 14:26:02
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# MDEV-7221 from_days fails after null value
#
...
...
mysql-test/t/func_hybrid_type.test
View file @
accf9b56
...
...
@@ -81,6 +81,38 @@ INSERT INTO t1 VALUES (4294967295,2015);
--
source
include
/
func_hybrid_type
.
inc
DROP
TABLE
t1
;
--
echo
#
SET
timestamp
=
UNIX_TIMESTAMP
(
'2001-01-01 01:02:03'
);
CREATE
TABLE
t1
(
a
DATE
,
b
TIME
);
INSERT
INTO
t1
VALUES
(
'2010-01-01'
,
'10:20:30'
);
--
source
include
/
func_hybrid_type
.
inc
DROP
TABLE
t1
;
SET
timestamp
=
DEFAULT
;
--
echo
#
SET
timestamp
=
UNIX_TIMESTAMP
(
'2001-01-01 01:02:03'
);
CREATE
TABLE
t1
(
a
TIMESTAMP
,
b
TIME
);
INSERT
INTO
t1
VALUES
(
'2010-01-01 00:00:00'
,
'10:20:30'
);
--
source
include
/
func_hybrid_type
.
inc
DROP
TABLE
t1
;
SET
timestamp
=
DEFAULT
;
--
echo
#
SET
timestamp
=
UNIX_TIMESTAMP
(
'2001-01-01 01:02:03'
);
CREATE
TABLE
t1
(
a
DATETIME
,
b
TIME
);
INSERT
INTO
t1
VALUES
(
'2010-01-01 00:00:00'
,
'10:20:30'
);
--
source
include
/
func_hybrid_type
.
inc
DROP
TABLE
t1
;
SET
timestamp
=
DEFAULT
;
--
echo
#
SET
timestamp
=
UNIX_TIMESTAMP
(
'2001-01-01 01:02:03'
);
CREATE
TABLE
t1
(
a
DATETIME
,
b
DATE
);
INSERT
INTO
t1
VALUES
(
'2010-01-01 10:20:30'
,
'2001-01-02'
);
--
source
include
/
func_hybrid_type
.
inc
DROP
TABLE
t1
;
SET
timestamp
=
DEFAULT
;
--
echo
#
--
echo
# MDEV-8873 Wrong field type or metadata for LEAST(int_column,string_column)
...
...
@@ -111,6 +143,28 @@ INSERT INTO t1 (a) VALUES (13836376518955650385) ON DUPLICATE KEY UPDATE a=GREAT
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
--
echo
#
--
echo
# MDEV-5694 GREATEST(date, time) returns a wrong data type
--
echo
#
SET
timestamp
=
UNIX_TIMESTAMP
(
'2010-01-01 01:02:03'
);
--
disable_ps_protocol
--
enable_metadata
# Expect DATETIME type (12) in metadata
SELECT
GREATEST
(
CURRENT_TIME
,
CURRENT_DATE
),
COALESCE
(
CURRENT_TIME
,
CURRENT_DATE
);
CREATE
TABLE
t1
(
a
TIMESTAMP
);
INSERT
INTO
t1
VALUES
(
'2010-01-01 10:20:30'
);
# Expect TIMESTAMP type (7) in metadata
SELECT
GREATEST
(
a
,
a
)
FROM
t1
;
DROP
TABLE
t1
;
--
disable_metadata
--
enable_ps_protocol
CREATE
TABLE
t1
(
a
TIMESTAMP
,
b
DATETIME
);
CREATE
TABLE
t2
AS
SELECT
LEAST
(
a
,
a
),
LEAST
(
b
,
b
),
LEAST
(
a
,
b
)
FROM
t1
;
SHOW
CREATE
TABLE
t2
;
DROP
TABLE
t2
;
DROP
TABLE
t1
;
SET
timestamp
=
DEFAULT
;
--
echo
#
--
echo
# End of 10.1 tests
--
echo
#
mysql-test/t/func_time.test
View file @
accf9b56
...
...
@@ -1180,6 +1180,7 @@ SET timestamp=UNIX_TIMESTAMP('2014-06-01 10:20:30');
select
greatest
(
cast
(
"0-0-0"
as
date
),
cast
(
"10:20:05"
as
time
));
select
greatest
(
cast
(
"0-0-0"
as
date
),
cast
(
"10:20:05"
as
time
))
=
'0000-00-00'
;
select
greatest
(
cast
(
"0-0-0"
as
date
),
cast
(
"10:20:05"
as
time
))
=
'2014-06-01'
;
select
greatest
(
cast
(
"0-0-0"
as
date
),
cast
(
"10:20:05"
as
time
))
=
'2014-06-01 10:20:05'
;
select
cast
(
greatest
(
cast
(
"0-0-0"
as
date
),
cast
(
"10:20:05"
as
time
))
as
datetime
(
6
));
SET
timestamp
=
DEFAULT
;
...
...
@@ -1629,11 +1630,12 @@ SET timestamp=DEFAULT;
--
echo
#
--
echo
# MDEV-5750 Assertion `ltime->year == 0' fails on a query with EXTRACT DAY_MINUTE and TIME column
--
echo
#
SET
timestamp
=
UNIX_TIMESTAMP
(
'2010-01-01 00:00:00'
);
CREATE
TABLE
t1
(
d
DATE
,
t
TIME
);
INSERT
INTO
t1
VALUES
(
'2008-12-05'
,
'22:34:09'
),(
'2005-03-27'
,
'14:26:02'
);
SELECT
EXTRACT
(
DAY_MINUTE
FROM
GREATEST
(
t
,
d
)),
GREATEST
(
t
,
d
)
FROM
t1
;
DROP
TABLE
t1
;
SET
timestamp
=
DEFAULT
;
--
echo
#
--
echo
# MDEV-7221 from_days fails after null value
...
...
sql/item_func.cc
View file @
accf9b56
...
...
@@ -2832,9 +2832,10 @@ void Item_func_min_max::fix_length_and_dec()
max_length
=
0
;
maybe_null
=
0
;
thd
=
current_thd
;
compare_as_dates
=
find_date_time_item
(
args
,
arg_count
,
0
);
Item_result
tmp_cmp_type
=
args
[
0
]
->
cmp_type
();
uint
string_type_count
=
0
;
uint
temporal_type_count
=
0
;
enum_field_types
temporal_field_type
=
MYSQL_TYPE_DATETIME
;
for
(
uint
i
=
0
;
i
<
arg_count
;
i
++
)
{
...
...
@@ -2846,6 +2847,15 @@ void Item_func_min_max::fix_length_and_dec()
maybe_null
=
1
;
tmp_cmp_type
=
item_cmp_type
(
tmp_cmp_type
,
args
[
i
]
->
cmp_type
());
string_type_count
+=
args
[
i
]
->
cmp_type
()
==
STRING_RESULT
;
if
(
args
[
i
]
->
cmp_type
()
==
TIME_RESULT
)
{
if
(
!
temporal_type_count
)
temporal_field_type
=
args
[
i
]
->
field_type
();
else
temporal_field_type
=
Field
::
field_type_merge
(
temporal_field_type
,
args
[
i
]
->
field_type
());
temporal_type_count
++
;
}
}
unsigned_flag
=
unsigned_count
==
arg_count
;
// if all args are unsigned
...
...
@@ -2853,12 +2863,11 @@ void Item_func_min_max::fix_length_and_dec()
case
TIME_RESULT
:
// At least one temporal argument was found.
collation
.
set_numeric
();
set_handler_by_field_type
(
compare_as_dates
->
field_type
());
if
(
mysql_type_to_time_type
(
Item_func_min_max
::
field_type
())
==
MYSQL_TIMESTAMP_DATE
)
decimals
=
0
;
else
set_handler_by_field_type
(
temporal_field_type
);
if
(
is_temporal_type_with_time
(
temporal_field_type
))
set_if_smaller
(
decimals
,
TIME_SECOND_PART_DIGITS
);
else
decimals
=
0
;
break
;
case
STRING_RESULT
:
...
...
@@ -2956,12 +2965,12 @@ bool Item_func_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
for example, SELECT MONTH(GREATEST("2011-11-21", "2010-10-09"))
*/
if
(
!
compare_as_dates
)
if
(
Item_func_min_max
::
cmp_type
()
!=
TIME_RESULT
)
return
Item_func
::
get_date
(
ltime
,
fuzzy_date
);
for
(
uint
i
=
0
;
i
<
arg_count
;
i
++
)
{
longlong
res
=
args
[
i
]
->
val_temporal_packed
(
compare_as_dates
);
longlong
res
=
args
[
i
]
->
val_temporal_packed
(
Item_func_min_max
::
field_type
()
);
/* Check if we need to stop (because of error or KILL) and stop the loop */
if
(
thd
->
is_error
()
||
args
[
i
]
->
null_value
)
...
...
@@ -2974,12 +2983,12 @@ bool Item_func_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
}
unpack_time
(
min_max
,
ltime
);
if
(
compare_as_dates
->
field_type
()
==
MYSQL_TYPE_DATE
)
if
(
Item_func_min_max
::
field_type
()
==
MYSQL_TYPE_DATE
)
{
ltime
->
time_type
=
MYSQL_TIMESTAMP_DATE
;
ltime
->
hour
=
ltime
->
minute
=
ltime
->
second
=
ltime
->
second_part
=
0
;
}
else
if
(
compare_as_dates
->
field_type
()
==
MYSQL_TYPE_TIME
)
else
if
(
Item_func_min_max
::
field_type
()
==
MYSQL_TYPE_TIME
)
{
ltime
->
time_type
=
MYSQL_TIMESTAMP_TIME
;
ltime
->
hour
+=
(
ltime
->
month
*
32
+
ltime
->
day
)
*
24
;
...
...
@@ -3001,7 +3010,7 @@ bool Item_func_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
String
*
Item_func_min_max
::
val_str
(
String
*
str
)
{
DBUG_ASSERT
(
fixed
==
1
);
if
(
compare_as_dates
)
if
(
Item_func_min_max
::
cmp_type
()
==
TIME_RESULT
)
return
val_string_from_date
(
str
);
switch
(
Item_func_min_max
::
result_type
())
{
case
INT_RESULT
:
...
...
@@ -3047,7 +3056,7 @@ double Item_func_min_max::val_real()
{
DBUG_ASSERT
(
fixed
==
1
);
double
value
=
0.0
;
if
(
compare_as_dates
)
if
(
Item_func_min_max
::
cmp_type
()
==
TIME_RESULT
)
{
MYSQL_TIME
ltime
;
if
(
get_date
(
&
ltime
,
0
))
...
...
@@ -3076,7 +3085,7 @@ longlong Item_func_min_max::val_int()
{
DBUG_ASSERT
(
fixed
==
1
);
longlong
value
=
0
;
if
(
compare_as_dates
)
if
(
Item_func_min_max
::
cmp_type
()
==
TIME_RESULT
)
{
MYSQL_TIME
ltime
;
if
(
get_date
(
&
ltime
,
0
))
...
...
@@ -3106,7 +3115,7 @@ my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
DBUG_ASSERT
(
fixed
==
1
);
my_decimal
tmp_buf
,
*
tmp
,
*
UNINIT_VAR
(
res
);
if
(
compare_as_dates
)
if
(
Item_func_min_max
::
cmp_type
()
==
TIME_RESULT
)
{
MYSQL_TIME
ltime
;
if
(
get_date
(
&
ltime
,
0
))
...
...
sql/item_func.h
View file @
accf9b56
...
...
@@ -1002,13 +1002,11 @@ class Item_func_min_max :public Item_func,
{
String
tmp_value
;
int
cmp_sign
;
/* An item used for issuing warnings while string to DATETIME conversion. */
Item
*
compare_as_dates
;
THD
*
thd
;
public:
Item_func_min_max
(
THD
*
thd
,
List
<
Item
>
&
list
,
int
cmp_sign_arg
)
:
Item_func
(
thd
,
list
),
cmp_sign
(
cmp_sign_arg
)
,
compare_as_dates
(
0
)
{}
Item_func
(
thd
,
list
),
cmp_sign
(
cmp_sign_arg
)
{}
double
val_real
();
longlong
val_int
();
String
*
val_str
(
String
*
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment