Column types are different. This is not correct. All data types were INT(3) in the above script. There are no any reasons why the data type for c3 should be shorter.
It seems CREATE TABLE erroneously used the user-specified display width (which is 3) when creating the column corresponding to CONCAT(f1(a)), while it correctly used the maximum possible width (which is 11) for CONCAT(a) and CONCAT(COALESCE(a)).
It should create varchar(11) for all three columns. The manual says:
The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using more than three digits.
The same problem is repeatable with stored aggregate functions:
CREATEORREPLACETABLE t1 (a INT);
INSERTINTO t1 VALUES (1),(2),(3);
DELIMITER $$
CREATEORREPLACE AGGREGATE FUNCTION f1(x INT) RETURNSINT(3)
BEGIN
DECLARE res INTDEFAULT 0;
DECLARECONTINUE HANDLER FORNOT FOUND RETURN res-200;
LOOP
FETCHGROUPNEXT ROW;
SET res= res + x;
END LOOP;
RETURN res;
END;
$$
DELIMITER ;
Now if I try to create a table from the same query, it fails:
SET sql_mode=STRICT_ALL_TABLES;
CREATEORREPLACETABLE t2 ASSELECT CONCAT(f1(a)) FROM t1;
ERROR 1406 (22001): Data too long for column 'CONCAT(f1(a))' at row 4
Retrying with a loose sql_mode:
SET sql_mode='';
CREATEORREPLACETABLE t2 ASSELECT CONCAT(f1(a)) FROM t1;
The data type for c1 is too long.
The data type for c2 is too short.
Alexander Barkov
added a comment - - edited A similar problem happens with TEXT variants:
CREATE OR REPLACE FUNCTION f1() RETURNS TINYTEXT CHARACTER SET utf8 RETURN '' ;
CREATE OR REPLACE TABLE t1 AS SELECT f1() AS c1, CONCAT(f1()) AS c2;
DESC t1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| c1 | longtext | YES | | NULL | |
| c2 | varchar(85) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
The data type for c1 is too long.
The data type for c2 is too short.
A similar problem happens with custom aggregate function returning TEXT variants:
DELIMITER $$
CREATEORREPLACE AGGREGATE FUNCTION f1() RETURNS TINYTEXT CHARACTERSET utf8
BEGIN
DECLARECONTINUE HANDLER FORNOT FOUND RETURN'';
LOOP
FETCHGROUPNEXT ROW;
END LOOP;
RETURN'';
END;
$$
DELIMITER ;
CREATEORREPLACETABLE t1 ASSELECT f1() AS c1;
DESC t1;
+-------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+-------+
| c1 | text | YES | | NULL | |
+-------+------+------+-----+---------+-------+
The data type text is wrong. It should be tinytext.
Alexander Barkov
added a comment - A similar problem happens with custom aggregate function returning TEXT variants:
DELIMITER $$
CREATE OR REPLACE AGGREGATE FUNCTION f1() RETURNS TINYTEXT CHARACTER SET utf8
BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN '' ;
LOOP
FETCH GROUP NEXT ROW;
END LOOP;
RETURN '' ;
END ;
$$
DELIMITER ;
CREATE OR REPLACE TABLE t1 AS SELECT f1() AS c1;
DESC t1;
+-------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+-------+
| c1 | text | YES | | NULL | |
+-------+------+------+-----+---------+-------+
The data type text is wrong. It should be tinytext .
People
Alexander Barkov
Alexander Barkov
Votes:
0Vote for this issue
Watchers:
2Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1315.1999998092651,"ttfb":407.1000003814697,"pageVisibility":"visible","entityId":66986,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"5f78ef56-bedf-4ba1-8bde-39c15fb5c5eb","navigationType":0,"readyForUser":1478.1999998092651,"redirectCount":0,"resourceLoadedEnd":1893.1000003814697,"resourceLoadedStart":412.1000003814697,"resourceTiming":[{"duration":314,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":412.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":412.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":726.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":313.8999996185303,"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":412.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":412.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":726.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":323,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":412.6000003814697,"connectEnd":412.6000003814697,"connectStart":412.6000003814697,"domainLookupEnd":412.6000003814697,"domainLookupStart":412.6000003814697,"fetchStart":412.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":412.6000003814697,"responseEnd":735.6000003814697,"responseStart":735.6000003814697,"secureConnectionStart":412.6000003814697},{"duration":438.6000003814697,"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":412.69999980926514,"connectEnd":412.69999980926514,"connectStart":412.69999980926514,"domainLookupEnd":412.69999980926514,"domainLookupStart":412.69999980926514,"fetchStart":412.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":412.69999980926514,"responseEnd":851.3000001907349,"responseStart":851.3000001907349,"secureConnectionStart":412.69999980926514},{"duration":448.19999980926514,"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":412.9000005722046,"connectEnd":412.9000005722046,"connectStart":412.9000005722046,"domainLookupEnd":412.9000005722046,"domainLookupStart":412.9000005722046,"fetchStart":412.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":412.9000005722046,"responseEnd":861.1000003814697,"responseStart":861.1000003814697,"secureConnectionStart":412.9000005722046},{"duration":448.9000005722046,"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":413.19999980926514,"connectEnd":413.19999980926514,"connectStart":413.19999980926514,"domainLookupEnd":413.19999980926514,"domainLookupStart":413.19999980926514,"fetchStart":413.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":413.19999980926514,"responseEnd":862.1000003814697,"responseStart":862.1000003814697,"secureConnectionStart":413.19999980926514},{"duration":449.1000003814697,"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":413.30000019073486,"connectEnd":413.30000019073486,"connectStart":413.30000019073486,"domainLookupEnd":413.30000019073486,"domainLookupStart":413.30000019073486,"fetchStart":413.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":413.30000019073486,"responseEnd":862.4000005722046,"responseStart":862.4000005722046,"secureConnectionStart":413.30000019073486},{"duration":521.7999992370605,"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":413.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":413.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":935.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":449.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":413.6000003814697,"connectEnd":413.6000003814697,"connectStart":413.6000003814697,"domainLookupEnd":413.6000003814697,"domainLookupStart":413.6000003814697,"fetchStart":413.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":413.6000003814697,"responseEnd":862.9000005722046,"responseStart":862.9000005722046,"secureConnectionStart":413.6000003814697},{"duration":521.6000003814697,"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":413.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":413.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":935.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":449.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":413.9000005722046,"connectEnd":413.9000005722046,"connectStart":413.9000005722046,"domainLookupEnd":413.9000005722046,"domainLookupStart":413.9000005722046,"fetchStart":413.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":413.9000005722046,"responseEnd":863.4000005722046,"responseStart":863.4000005722046,"secureConnectionStart":413.9000005722046},{"duration":788.5,"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":419.5,"connectEnd":419.5,"connectStart":419.5,"domainLookupEnd":419.5,"domainLookupStart":419.5,"fetchStart":419.5,"redirectEnd":0,"redirectStart":0,"requestStart":419.5,"responseEnd":1208,"responseStart":1208,"secureConnectionStart":419.5},{"duration":1446.8000001907349,"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":419.6000003814697,"connectEnd":419.6000003814697,"connectStart":419.6000003814697,"domainLookupEnd":419.6000003814697,"domainLookupStart":419.6000003814697,"fetchStart":419.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":419.6000003814697,"responseEnd":1866.4000005722046,"responseStart":1866.4000005722046,"secureConnectionStart":419.6000003814697},{"duration":321.30000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":961.6999998092651,"connectEnd":961.6999998092651,"connectStart":961.6999998092651,"domainLookupEnd":961.6999998092651,"domainLookupStart":961.6999998092651,"fetchStart":961.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":961.6999998092651,"responseEnd":1283,"responseStart":1283,"secureConnectionStart":961.6999998092651},{"duration":629.1999998092651,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1304.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1304.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1934.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":564.1999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1328.9000005722046,"connectEnd":1328.9000005722046,"connectStart":1328.9000005722046,"domainLookupEnd":1328.9000005722046,"domainLookupStart":1328.9000005722046,"fetchStart":1328.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":1328.9000005722046,"responseEnd":1893.1000003814697,"responseStart":1893.1000003814697,"secureConnectionStart":1328.9000005722046}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":231,"responseStart":407,"responseEnd":411,"domLoading":410,"domInteractive":1936,"domContentLoadedEventStart":1936,"domContentLoadedEventEnd":1994,"domComplete":2391,"loadEventStart":2391,"loadEventEnd":2392,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1870.8000001907349},{"name":"bigPipe.sidebar-id.end","time":1871.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1871.9000005722046},{"name":"bigPipe.activity-panel-pipe-id.end","time":1874},{"name":"activityTabFullyLoaded","time":2011.3000001907349}],"measures":[],"correlationId":"18ef49a77271ed","effectiveType":"4g","downlink":9.8,"rtt":0,"serverDuration":107,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
A similar problem happens with TEXT variants:
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| c1 | longtext | YES | | NULL | |
| c2 | varchar(85) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
The data type for c1 is too long.
The data type for c2 is too short.