Bug Description:
When inserting data into a table that has a BEFORE INSERT trigger, using an INSERT ... SELECT statement, the trigger is expected to populate the year column based on quarter. However, MariaDB returns an error stating that the column year cannot be null, even though the trigger sets its value.
This didn't have a problem previously.
Steps to Reproduce:
Create a test table:
CREATE TABLE `test_table` (
|
`year` int(11) NOT NULL,
|
`quarter` char(6) NOT NULL,
|
UNIQUE KEY `test_table_quarter` (`quarter`, `year`)
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
|
Create a BEFORE INSERT trigger:
|
|
DELIMITER $$
|
CREATE TRIGGER before_insert
|
BEFORE INSERT ON test_table
|
FOR EACH ROW
|
BEGIN
|
SET NEW.year = LEFT(NEW.quarter, 4);
|
END
|
$$
|
DELIMITER ;
|
Attempt an INSERT ... SELECT statement (Fails):
INSERT INTO test_table (year, quarter)
|
SELECT 2025 AS year, CONCAT('2025Q', seq) AS quarter FROM seq_1_to_4;
|
We are using a select from another table/view but here we can get the same 'bug' by just using a sequence.
Error:
Error Code: 1048. Column 'year' cannot be null
Manually inserting values (Works):
INSERT INTO test_table (`year`, `quarter`) VALUES ('2025', '2025Q1');
|
Expected Behavior:
The trigger should correctly populate the year column when using INSERT ... SELECT, just as it does when using INSERT ... VALUES.
Actual Behavior:
The INSERT ... SELECT statement fails because MariaDB treats year as NULL before the trigger executes, even though the trigger should set its value.
If you remove the trigger there is no problem, or if you insert a single row it works ok. The workaround in our case was to modify the insert to obtain the year rather than use the trigger.
It could be that this is intentional, however the behaviour has changed so I am reporting it.
Possibly
MDEV-36066: "v10.11.11 introduces bug that breaks production code - INSERT SELECT and triggers not working"
MDEV-36191: "Multi-row insert fails on table with update before trigger"
- duplicates
-
MDEV-36026
Problem with INSERT SELECT on NOT NULL columns while having BEFORE UPDATE trigger
-
-
Closed
{"report":{"fcp":1073.7000000476837,"ttfb":171,"pageVisibility":"visible","entityId":133306,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"f216cd8f-0721-4152-8aba-8bf4c89d3726","navigationType":0,"readyForUser":1146.2999999523163,"redirectCount":0,"resourceLoadedEnd":1461.5999999046326,"resourceLoadedStart":177.39999985694885,"resourceTiming":[{"duration":401.60000014305115,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":177.39999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":177.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":579,"responseStart":0,"secureConnectionStart":0},{"duration":401.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":177.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":177.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":579.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":411.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":177.79999995231628,"connectEnd":177.79999995231628,"connectStart":177.79999995231628,"domainLookupEnd":177.79999995231628,"domainLookupStart":177.79999995231628,"fetchStart":177.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":177.79999995231628,"responseEnd":589,"responseStart":589,"secureConnectionStart":177.79999995231628},{"duration":436.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":177.89999985694885,"connectEnd":177.89999985694885,"connectStart":177.89999985694885,"domainLookupEnd":177.89999985694885,"domainLookupStart":177.89999985694885,"fetchStart":177.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":177.89999985694885,"responseEnd":614.3999998569489,"responseStart":614.3999998569489,"secureConnectionStart":177.89999985694885},{"duration":439.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":178,"connectEnd":178,"connectStart":178,"domainLookupEnd":178,"domainLookupStart":178,"fetchStart":178,"redirectEnd":0,"redirectStart":0,"requestStart":178,"responseEnd":617.8999998569489,"responseStart":617.8999998569489,"secureConnectionStart":178},{"duration":440.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":178.09999990463257,"connectEnd":178.09999990463257,"connectStart":178.09999990463257,"domainLookupEnd":178.09999990463257,"domainLookupStart":178.09999990463257,"fetchStart":178.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":178.09999990463257,"responseEnd":618.2999999523163,"responseStart":618.2999999523163,"secureConnectionStart":178.09999990463257},{"duration":441.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":178.20000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":178.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":619.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":441.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":178.20000004768372,"connectEnd":178.20000004768372,"connectStart":178.20000004768372,"domainLookupEnd":178.20000004768372,"domainLookupStart":178.20000004768372,"fetchStart":178.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":178.20000004768372,"responseEnd":619.2999999523163,"responseStart":619.2999999523163,"secureConnectionStart":178.20000004768372},{"duration":441.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":178.39999985694885,"connectEnd":178.39999985694885,"connectStart":178.39999985694885,"domainLookupEnd":178.39999985694885,"domainLookupStart":178.39999985694885,"fetchStart":178.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":178.39999985694885,"responseEnd":619.7000000476837,"responseStart":619.7000000476837,"secureConnectionStart":178.39999985694885},{"duration":442.2000000476837,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":178.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":178.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":620.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":442.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":178.70000004768372,"connectEnd":178.70000004768372,"connectStart":178.70000004768372,"domainLookupEnd":178.70000004768372,"domainLookupStart":178.70000004768372,"fetchStart":178.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":178.70000004768372,"responseEnd":620.7999999523163,"responseStart":620.7999999523163,"secureConnectionStart":178.70000004768372},{"duration":1280.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":179.39999985694885,"connectEnd":179.39999985694885,"connectStart":179.39999985694885,"domainLookupEnd":179.39999985694885,"domainLookupStart":179.39999985694885,"fetchStart":179.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":179.39999985694885,"responseEnd":1460.0999999046326,"responseStart":1460.0999999046326,"secureConnectionStart":179.39999985694885},{"duration":1282.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":179.5,"connectEnd":179.5,"connectStart":179.5,"domainLookupEnd":179.5,"domainLookupStart":179.5,"fetchStart":179.5,"redirectEnd":0,"redirectStart":0,"requestStart":179.5,"responseEnd":1461.5999999046326,"responseStart":1461.5999999046326,"secureConnectionStart":179.5},{"duration":550.5999999046326,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":854.5,"connectEnd":854.5,"connectStart":854.5,"domainLookupEnd":854.5,"domainLookupStart":854.5,"fetchStart":854.5,"redirectEnd":0,"redirectStart":0,"requestStart":854.5,"responseEnd":1405.0999999046326,"responseStart":1405.0999999046326,"secureConnectionStart":854.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":17,"responseStart":171,"responseEnd":174,"domLoading":175,"domInteractive":1513,"domContentLoadedEventStart":1513,"domContentLoadedEventEnd":1549,"domComplete":2596,"loadEventStart":2596,"loadEventEnd":2598,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1497.5999999046326},{"name":"bigPipe.sidebar-id.end","time":1498.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":1498.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1500.8999998569489},{"name":"activityTabFullyLoaded","time":1556.3999998569489}],"measures":[],"correlationId":"b3e1d755b5b7b8","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":98,"dbReadsTimeInMs":14,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}