DROP TABLE IF EXISTS t1,t2;
|
CREATE TABLE t1 (dt2 DATETIME(2), t3 TIME(3), d DATE);
|
INSERT INTO t1 VALUES ('2001-01-01 00:00:00.12', '00:00:00.567', '2002-01-01');
|
SELECT CASE WHEN 0 THEN dt2 ELSE t3 END FROM t1;
|
CREATE TABLE t2 AS SELECT CASE WHEN 0 THEN dt2 ELSE t3 END FROM t1;
|
SELECT * FROM t2;
|
SHOW COLUMNS FROM t2;
|
+----------------------------------+
|
| CASE WHEN 0 THEN dt2 ELSE t3 END |
|
+----------------------------------+
|
| NULL |
|
+----------------------------------+
|
+----------------------------------+
|
| CASE WHEN 0 THEN dt2 ELSE t3 END |
|
+----------------------------------+
|
| 0000-00-00 00:00:00.000 |
|
+----------------------------------+
|
+----------------------------------+-------------+------+-----+---------+-------+
|
| Field | Type | Null | Key | Default | Extra |
|
+----------------------------------+-------------+------+-----+---------+-------+
|
| CASE WHEN 0 THEN dt2 ELSE t3 END | datetime(3) | YES | | NULL | |
|
+----------------------------------+-------------+------+-----+---------+-------
|
Notice, CASE correctly creates a DATETIME(3) column.
However, it returns wrong values from both SELECT queries.
The expected value is:
'0000-00-00 '00:00:00.567'
More examples:
SELECT CASE WHEN 1 THEN dt2 ELSE t3 END FROM t1;
|
+----------------------------------+
|
| CASE WHEN 1 THEN dt2 ELSE t3 END |
|
+----------------------------------+
|
| 2001-01-01 00:00:00.120 |
|
+----------------------------------+
|
SELECT CONCAT(CASE WHEN 1 THEN dt2 ELSE t3 END) FROM t1;
|
+------------------------------------------+
|
| CONCAT(CASE WHEN 1 THEN dt2 ELSE t3 END) |
|
+------------------------------------------+
|
| 2001-01-01 00:00:00.12 |
|
+------------------------------------------+
|
The expected result is '2001-01-01 00:00:00.120' for both queries.
SELECT CONCAT(CASE WHEN 0 THEN t3 ELSE dt2 END) FROM t1;
|
+------------------------------------------+
|
| CONCAT(CASE WHEN 0 THEN t3 ELSE dt2 END) |
|
+------------------------------------------+
|
| 2001-01-01 00:00:00.12 |
|
+------------------------------------------+
|
The expected result is '2001-01-01 00:00:00.120'.
SELECT CONCAT(CASE WHEN 1 THEN d ELSE t3 END) FROM t1;
|
+----------------------------------------+
|
| CONCAT(CASE WHEN 1 THEN d ELSE t3 END) |
|
+----------------------------------------+
|
| 2002-01-01 |
|
+----------------------------------------+
|
The expected result is '2002-01-01 00:00:00'.
SELECT CASE WHEN 1 THEN t3 ELSE d END FROM t1;
|
+--------------------------------+
|
| CASE WHEN 1 THEN t3 ELSE d END |
|
+--------------------------------+
|
| NULL |
|
+--------------------------------+
|
SHOW WARNINGS;
|
+---------+------+------------------------------------------+
|
| Level | Code | Message |
|
+---------+------+------------------------------------------+
|
| Warning | 1292 | Incorrect datetime value: '00:00:00.567' |
|
+---------+------+------------------------------------------+
|
The expected result is '0000-00-00 00:00:00.567', without a warning.
A similar problem is observed with COALESCE:
SELECT COALESCE(d, t3) FROM t1;
|
+-------------------------+
|
| COALESCE(d, t3) |
|
+-------------------------+
|
| 2002-01-01 00:00:00.000 |
|
+-------------------------+
|
SELECT CONCAT(COALESCE(d, t3)) FROM t1;
|
+-------------------------+
|
| CONCAT(COALESCE(d, t3)) |
|
+-------------------------+
|
| 2002-01-01 |
|
+-------------------------+
|
The expected result is '2002-01-01 00:00:00.000' for both queries.
SELECT COALESCE(dt2, t3) FROM t1;
|
+-------------------------+
|
| COALESCE(dt2, t3) |
|
+-------------------------+
|
| 2001-01-01 00:00:00.120 |
|
+-------------------------+
|
SELECT CONCAT(COALESCE(dt2, t3)) FROM t1;
|
+---------------------------+
|
| CONCAT(COALESCE(dt2, t3)) |
|
+---------------------------+
|
| 2001-01-01 00:00:00.12 |
|
+---------------------------+
|
The expected result is '2001-01-01 00:00:00.120' for both queries.
A similar problems is observer with IFNULL:
SELECT IFNULL(dt2, t3), CONCAT(IFNULL(dt2, t3)) FROM t1;
|
+-------------------------+-------------------------+
|
| IFNULL(dt2, t3) | CONCAT(IFNULL(dt2, t3)) |
|
+-------------------------+-------------------------+
|
| 2001-01-01 00:00:00.120 | 2001-01-01 00:00:00.12 |
|
+-------------------------+-------------------------+
|
The expected value is '2001-01-01 00:00:00.120' for both expressions.
SELECT IFNULL(d, t3), CONCAT(IFNULL(d, t3)) FROM t1;
|
+-------------------------+-----------------------+
|
| IFNULL(d, t3) | CONCAT(IFNULL(d, t3)) |
|
+-------------------------+-----------------------+
|
| 2002-01-01 00:00:00.000 | 2002-01-01 |
|
+-------------------------+-----------------------+
|
The expected value is '2002-01-01 00:00:00.000' for both expressions.
- duplicates
-
MDEV-4863
COALESCE(time_or_datetime) returns wrong results in numeric context
-
-
Closed
{"report":{"fcp":875,"ttfb":239.30000019073486,"pageVisibility":"visible","entityId":25059,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"a4094414-56a4-4c4a-9905-37f3b4de3b1f","navigationType":0,"readyForUser":975.9000000953674,"redirectCount":0,"resourceLoadedEnd":1096.7000002861023,"resourceLoadedStart":244.2000002861023,"resourceTiming":[{"duration":100.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":244.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":244.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":344.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":101.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":244.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":244.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":346.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":169.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":244.7000002861023,"connectEnd":244.7000002861023,"connectStart":244.7000002861023,"domainLookupEnd":244.7000002861023,"domainLookupStart":244.7000002861023,"fetchStart":244.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":244.7000002861023,"responseEnd":414.59999990463257,"responseStart":414.59999990463257,"secureConnectionStart":244.7000002861023},{"duration":218.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":244.80000019073486,"connectEnd":244.80000019073486,"connectStart":244.80000019073486,"domainLookupEnd":244.80000019073486,"domainLookupStart":244.80000019073486,"fetchStart":244.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":244.80000019073486,"responseEnd":462.90000009536743,"responseStart":462.90000009536743,"secureConnectionStart":244.80000019073486},{"duration":221.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":245.09999990463257,"connectEnd":245.09999990463257,"connectStart":245.09999990463257,"domainLookupEnd":245.09999990463257,"domainLookupStart":245.09999990463257,"fetchStart":245.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":245.09999990463257,"responseEnd":466.80000019073486,"responseStart":466.80000019073486,"secureConnectionStart":245.09999990463257},{"duration":222,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":245.30000019073486,"connectEnd":245.30000019073486,"connectStart":245.30000019073486,"domainLookupEnd":245.30000019073486,"domainLookupStart":245.30000019073486,"fetchStart":245.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":245.30000019073486,"responseEnd":467.30000019073486,"responseStart":467.2000002861023,"secureConnectionStart":245.30000019073486},{"duration":222.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":245.5,"connectEnd":245.5,"connectStart":245.5,"domainLookupEnd":245.5,"domainLookupStart":245.5,"fetchStart":245.5,"redirectEnd":0,"redirectStart":0,"requestStart":245.5,"responseEnd":467.59999990463257,"responseStart":467.59999990463257,"secureConnectionStart":245.5},{"duration":313.6000003814697,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":245.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":245.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":559.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":222.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":245.80000019073486,"connectEnd":245.80000019073486,"connectStart":245.80000019073486,"domainLookupEnd":245.80000019073486,"domainLookupStart":245.80000019073486,"fetchStart":245.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":245.80000019073486,"responseEnd":468,"responseStart":468,"secureConnectionStart":245.80000019073486},{"duration":313.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":245.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":245.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":559.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":222.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":246.09999990463257,"connectEnd":246.09999990463257,"connectStart":246.09999990463257,"domainLookupEnd":246.09999990463257,"domainLookupStart":246.09999990463257,"fetchStart":246.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":246.09999990463257,"responseEnd":468.59999990463257,"responseStart":468.59999990463257,"secureConnectionStart":246.09999990463257},{"duration":826.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":251.80000019073486,"connectEnd":251.80000019073486,"connectStart":251.80000019073486,"domainLookupEnd":251.80000019073486,"domainLookupStart":251.80000019073486,"fetchStart":251.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":251.80000019073486,"responseEnd":1078.5,"responseStart":1078.5,"secureConnectionStart":251.80000019073486},{"duration":827.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":252.2000002861023,"connectEnd":252.2000002861023,"connectStart":252.2000002861023,"domainLookupEnd":252.2000002861023,"domainLookupStart":252.2000002861023,"fetchStart":252.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":252.2000002861023,"responseEnd":1079.5999999046326,"responseStart":1079.5999999046326,"secureConnectionStart":252.2000002861023},{"duration":507.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":571.4000000953674,"connectEnd":571.4000000953674,"connectStart":571.4000000953674,"domainLookupEnd":571.4000000953674,"domainLookupStart":571.4000000953674,"fetchStart":571.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":571.4000000953674,"responseEnd":1079.2000002861023,"responseStart":1079.2000002861023,"secureConnectionStart":571.4000000953674},{"duration":235.80000019073486,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":868.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":868.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1104.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":14.100000381469727,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&slack-enabled=true&whisper-enabled=true","startTime":1082.5999999046326,"connectEnd":1082.5999999046326,"connectStart":1082.5999999046326,"domainLookupEnd":1082.5999999046326,"domainLookupStart":1082.5999999046326,"fetchStart":1082.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1082.5999999046326,"responseEnd":1096.7000002861023,"responseStart":1096.7000002861023,"secureConnectionStart":1082.5999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":68,"responseStart":240,"responseEnd":250,"domLoading":243,"domInteractive":1161,"domContentLoadedEventStart":1161,"domContentLoadedEventEnd":1215,"domComplete":1450,"loadEventStart":1450,"loadEventEnd":1451,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1147.5999999046326},{"name":"bigPipe.sidebar-id.end","time":1148.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1148.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":1149.7000002861023},{"name":"activityTabFullyLoaded","time":1231.0999999046326}],"measures":[],"correlationId":"7a3354666ce773","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":99,"dbReadsTimeInMs":14,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The problem was earlier fixed by:
MDEV-4863COALESCE(time_or_datetime) returns wrong results in numeric context