For one-row statements, the SET clause may be more simple, because you don't need to remember the columns order. All values are specified in the form col = expr.
Values can also be specified in the form of a SQL expression or subquery. However, the subquery cannot access the same table that is named in the INTO clause.
Does the last paragraph refer to INSERT ... SET syntax or INSERT ... VALUES syntax?
According to Igor, one cannot refer to inserted-into table from subquery.
However here 's a counter example from Rex:
MariaDB [test]> INSERT INTO t1 (t1a) values ( 1 + (select t1a from t2 where (select t3a from t3 where t3.t3a > t1.t1a) ) );
Query OK, 1 row affected (0.007 sec)
Sergei Petrunia
added a comment - Take-aways from yesterday call: It seems the above behavior was added intentionally, see:
commit c7320830a62b0ed3245c476f074c534d3cd20027
Author: Sergei Golubchik <serg@mariadb.org>
Date: Tue Sep 24 19:47:45 2019 +0200
outer references in subqueries in INSERT
remove inconsistent limitation
the meaning of
INSERT INTO t1 VALUES (t1_col);
is "insert a row with default value of t1_col1".
https://mariadb.com/kb/en/insert/ has this:
For one-row statements, the SET clause may be more simple, because you don't need to remember the columns order. All values are specified in the form col = expr.
Values can also be specified in the form of a SQL expression or subquery. However, the subquery cannot access the same table that is named in the INTO clause.
Does the last paragraph refer to INSERT ... SET syntax or INSERT ... VALUES syntax?
According to Igor, one cannot refer to inserted-into table from subquery.
However here 's a counter example from Rex:
MariaDB [test]> INSERT INTO t1 (t1a) values ( 1 + (select t1a from t2 where (select t3a from t3 where t3.t3a > t1.t1a) ) );
Query OK, 1 row affected (0.007 sec)
After SQL processor meeting discussion: possibility to reference a column of a table from VALUES of an INSERT is not a bug but a feature. In this case the default value of the column is taken. MySQL supports this too.
Oleg Smirnov
added a comment - After SQL processor meeting discussion: possibility to reference a column of a table from VALUES of an INSERT is not a bug but a feature. In this case the default value of the column is taken. MySQL supports this too.
People
Oleksandr Byelkin
Oleg Smirnov
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":1507.7000000476837,"ttfb":805.2000000476837,"pageVisibility":"visible","entityId":132384,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"fd67c87f-0acc-4304-b673-88650247034d","navigationType":0,"readyForUser":1578.5999999046326,"redirectCount":0,"resourceLoadedEnd":1219.2999999523163,"resourceLoadedStart":814.0999999046326,"resourceTiming":[{"duration":107.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":814.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":814.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":922,"responseStart":0,"secureConnectionStart":0},{"duration":107.90000009536743,"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":814.3999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":814.3999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":922.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":300.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":814.5999999046326,"connectEnd":924.2999999523163,"connectStart":924.2999999523163,"domainLookupEnd":924.2999999523163,"domainLookupStart":924.2999999523163,"fetchStart":814.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":925.0999999046326,"responseEnd":1115,"responseStart":938.0999999046326,"secureConnectionStart":924.2999999523163},{"duration":404.2000000476837,"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":815.0999999046326,"connectEnd":815.0999999046326,"connectStart":815.0999999046326,"domainLookupEnd":815.0999999046326,"domainLookupStart":815.0999999046326,"fetchStart":815.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":925.5,"responseEnd":1219.2999999523163,"responseStart":941.3999998569489,"secureConnectionStart":815.0999999046326},{"duration":132.29999995231628,"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":815.2000000476837,"connectEnd":815.2000000476837,"connectStart":815.2000000476837,"domainLookupEnd":815.2000000476837,"domainLookupStart":815.2000000476837,"fetchStart":815.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":926.2999999523163,"responseEnd":947.5,"responseStart":945.3999998569489,"secureConnectionStart":815.2000000476837},{"duration":138.5,"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":815.2999999523163,"connectEnd":815.2999999523163,"connectStart":815.2999999523163,"domainLookupEnd":815.2999999523163,"domainLookupStart":815.2999999523163,"fetchStart":815.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":928.5,"responseEnd":953.7999999523163,"responseStart":947.7999999523163,"secureConnectionStart":815.2999999523163},{"duration":139.09999990463257,"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":815.2999999523163,"connectEnd":815.2999999523163,"connectStart":815.2999999523163,"domainLookupEnd":815.2999999523163,"domainLookupStart":815.2999999523163,"fetchStart":815.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":927.8999998569489,"responseEnd":954.3999998569489,"responseStart":949.3999998569489,"secureConnectionStart":815.2999999523163},{"duration":111.89999985694885,"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":815.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":815.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":927.3999998569489,"responseStart":0,"secureConnectionStart":0},{"duration":145.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":815.5,"connectEnd":815.5,"connectStart":815.5,"domainLookupEnd":815.5,"domainLookupStart":815.5,"fetchStart":815.5,"redirectEnd":0,"redirectStart":0,"requestStart":929.3999998569489,"responseEnd":960.7999999523163,"responseStart":955.2999999523163,"secureConnectionStart":815.5},{"duration":113.10000014305115,"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":815.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":815.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":928.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":149.5,"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":815.7999999523163,"connectEnd":815.7999999523163,"connectStart":815.7999999523163,"domainLookupEnd":815.7999999523163,"domainLookupStart":815.7999999523163,"fetchStart":815.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":930.7999999523163,"responseEnd":965.2999999523163,"responseStart":956.2000000476837,"secureConnectionStart":815.7999999523163},{"duration":372.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":820.5,"connectEnd":820.5,"connectStart":820.5,"domainLookupEnd":820.5,"domainLookupStart":820.5,"fetchStart":820.5,"redirectEnd":0,"redirectStart":0,"requestStart":1084.2999999523163,"responseEnd":1193.2000000476837,"responseStart":1185.7000000476837,"secureConnectionStart":820.5},{"duration":372.2000000476837,"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":822,"connectEnd":822,"connectStart":822,"domainLookupEnd":822,"domainLookupStart":822,"fetchStart":822,"redirectEnd":0,"redirectStart":0,"requestStart":1118.7999999523163,"responseEnd":1194.2000000476837,"responseStart":1189,"secureConnectionStart":822},{"duration":95.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1263.5999999046326,"connectEnd":1263.5999999046326,"connectStart":1263.5999999046326,"domainLookupEnd":1263.5999999046326,"domainLookupStart":1263.5999999046326,"fetchStart":1263.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1328.8999998569489,"responseEnd":1359.0999999046326,"responseStart":1358.2000000476837,"secureConnectionStart":1263.5999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":476,"responseStart":806,"responseEnd":822,"domLoading":809,"domInteractive":1671,"domContentLoadedEventStart":1671,"domContentLoadedEventEnd":1717,"domComplete":2655,"loadEventStart":2655,"loadEventEnd":2655,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1649.2999999523163},{"name":"bigPipe.sidebar-id.end","time":1650.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1650.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":1651.7000000476837},{"name":"activityTabFullyLoaded","time":1733.8999998569489}],"measures":[],"correlationId":"b6207f87f0bbfd","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":69,"dbReadsTimeInMs":10,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Take-aways from yesterday call: It seems the above behavior was added intentionally, see:
commit c7320830a62b0ed3245c476f074c534d3cd20027
Author: Sergei Golubchik <serg@mariadb.org>
Date: Tue Sep 24 19:47:45 2019 +0200
outer references in subqueries in INSERT
remove inconsistent limitation
the meaning of
INSERT INTO t1 VALUES (t1_col);
is "insert a row with default value of t1_col1".
https://mariadb.com/kb/en/insert/ has this:
Does the last paragraph refer to INSERT ... SET syntax or INSERT ... VALUES syntax?
According to Igor, one cannot refer to inserted-into table from subquery.
However here 's a counter example from Rex:
MariaDB [test]> INSERT INTO t1 (t1a) values ( 1 + (select t1a from t2 where (select t3a from t3 where t3.t3a > t1.t1a) ) );
Query OK, 1 row affected (0.007 sec)