ADDTIME(expr1,expr2) is a hybrid function.
- In case when expr1 is DATETIME, the result type is DATETIME.
- In case when expr1 is TIME, the result type is TIME.
- Otherwise, the result type is VARCHAR, and the choice between
DATETIME or TIME format is done per-row.
In case of VARCHAR result, the function must follow the standard
MySQL/MariaDB convention:
character set and collation of a string function returning a result
from numeric or temporal input should be set according to
@@character_set_connection and @@collation_connection
respectively.
http://dev.mysql.com/doc/refman/5.6/en/type-conversion.html
In MySQL 5.6, implicit conversion of a numeric or temporal value to string produces a value that has a character set and collation determined by the character_set_connection and collation_connection system variables.
Consider this SQL script:
set character_set_connection=ucs2;
|
select charset(addtime(_latin1'10:01:01',_latin1'10:00:00'));
|
drop table if exists t1;
|
create table t1 as select addtime(_latin1'10:01:01',_latin1'10:00:00') as a;
|
show create table t1;
|
MySQL-5.6 does follow this rule, and the output is:
+-------------------------------------------------------+
|
| charset(addtime(_latin1'10:01:01',_latin1'10:00:00')) |
|
+-------------------------------------------------------+
|
| ucs2 |
|
+-------------------------------------------------------+
|
1
|
+-------+--------------------------------------------------------------------------------------------
|
|
...
|
|
------------------+
|
| Table | Create Table |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(29) CHARACTER SET ucs2 DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
Notice: ucs2 is consistently reported in both tables in the output.
MariaDB does not follow this rule, and the output is:
+-------------------------------------------------------+
|
| charset(addtime(_latin1'10:01:01',_latin1'10:00:00')) |
|
+-------------------------------------------------------+
|
| binary |
|
+-------------------------------------------------------+
|
|
...
|
|
+-------+-------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+-------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(26) DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+-------------------------------------------------------------------------------------------
|
Moreover, the result of CHARSET() and of "SHOW CREATE" do not
match to each over (binary vs latin1).
The same problem is observed with another temporal hybrid function DATE_ADD.
The script:
set character_set_connection=ucs2;
|
select charset(date_add(_latin1'10:01:01',interval 10 second));
|
drop table if exists t1;
|
create table t1 as select date_add(_latin1'10:01:01',interval 10 second) as a;
|
show create table t1;
|
Results from MySQL-5.6 are consistently correct:
+---------------------------------------------------------+
|
| charset(date_add(_latin1'10:01:01',interval 10 second)) |
|
+---------------------------------------------------------+
|
| ucs2 |
|
+---------------------------------------------------------+
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(29) CHARACTER SET ucs2 DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
Result from MariaDB-10.0 are wrong and non-consistent:
+---------------------------------------------------------+
|
| charset(date_add(_latin1'10:01:01',interval 10 second)) |
|
+---------------------------------------------------------+
|
| binary |
|
+---------------------------------------------------------+
|
+-------+-------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+-------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(26) DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+-------------------------------------------------------------------------------------------+
|
|
{"report":{"fcp":1387.6000000014901,"ttfb":653.7000000029802,"pageVisibility":"visible","entityId":25025,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"0635a1c5-4a6e-4bba-8ec7-a0a2129fc0c5","navigationType":0,"readyForUser":1476.3999999985099,"redirectCount":0,"resourceLoadedEnd":1843,"resourceLoadedStart":658.6000000014901,"resourceTiming":[{"duration":269.8999999985099,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":658.6000000014901,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":658.6000000014901,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":928.5,"responseStart":0,"secureConnectionStart":0},{"duration":269.90000000596046,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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","startTime":658.8999999985099,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":658.8999999985099,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":928.8000000044703,"responseStart":0,"secureConnectionStart":0},{"duration":282.6000000014901,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":659.1000000014901,"connectEnd":659.1000000014901,"connectStart":659.1000000014901,"domainLookupEnd":659.1000000014901,"domainLookupStart":659.1000000014901,"fetchStart":659.1000000014901,"redirectEnd":0,"redirectStart":0,"requestStart":659.1000000014901,"responseEnd":941.7000000029802,"responseStart":941.7000000029802,"secureConnectionStart":659.1000000014901},{"duration":351.19999999552965,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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","startTime":659.2000000029802,"connectEnd":659.2000000029802,"connectStart":659.2000000029802,"domainLookupEnd":659.2000000029802,"domainLookupStart":659.2000000029802,"fetchStart":659.2000000029802,"redirectEnd":0,"redirectStart":0,"requestStart":659.2000000029802,"responseEnd":1010.3999999985099,"responseStart":1010.3999999985099,"secureConnectionStart":659.2000000029802},{"duration":354.90000000596046,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":659.3999999985099,"connectEnd":659.3999999985099,"connectStart":659.3999999985099,"domainLookupEnd":659.3999999985099,"domainLookupStart":659.3999999985099,"fetchStart":659.3999999985099,"redirectEnd":0,"redirectStart":0,"requestStart":659.3999999985099,"responseEnd":1014.3000000044703,"responseStart":1014.3000000044703,"secureConnectionStart":659.3999999985099},{"duration":355.1000000014901,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":659.6000000014901,"connectEnd":659.6000000014901,"connectStart":659.6000000014901,"domainLookupEnd":659.6000000014901,"domainLookupStart":659.6000000014901,"fetchStart":659.6000000014901,"redirectEnd":0,"redirectStart":0,"requestStart":659.6000000014901,"responseEnd":1014.7000000029802,"responseStart":1014.7000000029802,"secureConnectionStart":659.6000000014901},{"duration":355.3999999985099,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":659.8000000044703,"connectEnd":659.8000000044703,"connectStart":659.8000000044703,"domainLookupEnd":659.8000000044703,"domainLookupStart":659.8000000044703,"fetchStart":659.8000000044703,"redirectEnd":0,"redirectStart":0,"requestStart":659.8000000044703,"responseEnd":1015.2000000029802,"responseStart":1015.2000000029802,"secureConnectionStart":659.8000000044703},{"duration":423.20000000298023,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":660,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":660,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1083.2000000029802,"responseStart":0,"secureConnectionStart":0},{"duration":355.3999999985099,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":660.2000000029802,"connectEnd":660.2000000029802,"connectStart":660.2000000029802,"domainLookupEnd":660.2000000029802,"domainLookupStart":660.2000000029802,"fetchStart":660.2000000029802,"redirectEnd":0,"redirectStart":0,"requestStart":660.2000000029802,"responseEnd":1015.6000000014901,"responseStart":1015.6000000014901,"secureConnectionStart":660.2000000029802},{"duration":423.09999999403954,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":660.3000000044703,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":660.3000000044703,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1083.3999999985099,"responseStart":0,"secureConnectionStart":0},{"duration":355.6000000014901,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":660.5,"connectEnd":660.5,"connectStart":660.5,"domainLookupEnd":660.5,"domainLookupStart":660.5,"fetchStart":660.5,"redirectEnd":0,"redirectStart":0,"requestStart":660.5,"responseEnd":1016.1000000014901,"responseStart":1016.1000000014901,"secureConnectionStart":660.5},{"duration":739.8000000044703,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":666,"connectEnd":666,"connectStart":666,"domainLookupEnd":666,"domainLookupStart":666,"fetchStart":666,"redirectEnd":0,"redirectStart":0,"requestStart":666,"responseEnd":1405.8000000044703,"responseStart":1405.8000000044703,"secureConnectionStart":666},{"duration":1176.8999999985099,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":666.1000000014901,"connectEnd":666.1000000014901,"connectStart":666.1000000014901,"domainLookupEnd":666.1000000014901,"domainLookupStart":666.1000000014901,"fetchStart":666.1000000014901,"redirectEnd":0,"redirectStart":0,"requestStart":666.1000000014901,"responseEnd":1843,"responseStart":1843,"secureConnectionStart":666.1000000014901},{"duration":313.29999999701977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1094.6000000014901,"connectEnd":1094.6000000014901,"connectStart":1094.6000000014901,"domainLookupEnd":1094.6000000014901,"domainLookupStart":1094.6000000014901,"fetchStart":1094.6000000014901,"redirectEnd":0,"redirectStart":0,"requestStart":1094.6000000014901,"responseEnd":1407.8999999985099,"responseStart":1407.8999999985099,"secureConnectionStart":1094.6000000014901},{"duration":523.6999999955297,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1381.7000000029802,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1381.7000000029802,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1905.3999999985099,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":123,"responseStart":653,"responseEnd":658,"domLoading":657,"domInteractive":1863,"domContentLoadedEventStart":1863,"domContentLoadedEventEnd":1905,"domComplete":3712,"loadEventStart":3712,"loadEventEnd":3714,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1846.8999999985099},{"name":"bigPipe.sidebar-id.end","time":1847.8000000044703},{"name":"bigPipe.activity-panel-pipe-id.start","time":1848},{"name":"bigPipe.activity-panel-pipe-id.end","time":1850.2000000029802},{"name":"activityTabFullyLoaded","time":1912.3000000044703}],"measures":[],"correlationId":"45c0237b763e23","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":460,"dbReadsTimeInMs":8,"dbConnsTimeInMs":15,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}