It would be useful, similar to the OUTPUT clause in MSSQL, if we could INSERT the data sent back from a returning clause in a single statement. Something like…
CREATE TABLE deleted_ids
(
Id INT NOT NULL PRIMARY KEY
);
INSERT INTO deleted_ids
DELETE FROM t1
WHERE id < 999
RETURNING id;
Attachments
Issue Links
relates to
MDEV-8347Allow DELETE RETURNING to be used inside stored procedures
This is how it looks like in PostgreSQL. Note the use of CTE (MDEV-8308)
postgres=# SELECT * FROM t1;
id | myarray
----+---------
1 | {1,2,4}
(1 row)
postgres=# SELECT * FROM t2;
id | myarray
----+---------
(0 rows)
postgres=# WITH del_t1 AS (DELETE FROM t1 RETURNING *)
INSERT INTO t2 SELECT * FROM del_t1;
INSERT 0 1
postgres=# SELECT * FROM t1;
id | myarray
----+---------
(0 rows)
postgres=# SELECT * FROM t2;
id | myarray
----+---------
1 | {1,2,4}
(1 row)
Daniël van Eeden
added a comment - This is how it looks like in PostgreSQL. Note the use of CTE ( MDEV-8308 )
postgres=# SELECT * FROM t1;
id | myarray
----+---------
1 | {1,2,4}
(1 row)
postgres=# SELECT * FROM t2;
id | myarray
----+---------
(0 rows)
postgres=# WITH del_t1 AS (DELETE FROM t1 RETURNING *)
INSERT INTO t2 SELECT * FROM del_t1;
INSERT 0 1
postgres=# SELECT * FROM t1;
id | myarray
----+---------
(0 rows)
postgres=# SELECT * FROM t2;
id | myarray
----+---------
1 | {1,2,4}
(1 row)
People
Unassigned
Geoff Montee (Inactive)
Votes:
8Vote for this issue
Watchers:
6Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":698.2000000476837,"ttfb":155.59999990463257,"pageVisibility":"visible","entityId":51697,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"2b6174b6-f0cf-488f-ac96-c2d712d8deeb","navigationType":0,"readyForUser":753.8999998569489,"redirectCount":0,"resourceLoadedEnd":279.2000000476837,"resourceLoadedStart":162.89999985694885,"resourceTiming":[{"duration":3.700000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":162.89999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":162.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":166.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":6.199999809265137,"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":163.20000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":163.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":169.39999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":93.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":163.29999995231628,"connectEnd":163.29999995231628,"connectStart":163.29999995231628,"domainLookupEnd":163.29999995231628,"domainLookupStart":163.29999995231628,"fetchStart":163.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":172.89999985694885,"responseEnd":257.09999990463257,"responseStart":211,"secureConnectionStart":163.29999995231628},{"duration":61.59999990463257,"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":163.5,"connectEnd":163.5,"connectStart":163.5,"domainLookupEnd":163.5,"domainLookupStart":163.5,"fetchStart":163.5,"redirectEnd":0,"redirectStart":0,"requestStart":174.70000004768372,"responseEnd":225.09999990463257,"responseStart":224.5,"secureConnectionStart":163.5},{"duration":115.70000004768372,"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":163.5,"connectEnd":163.5,"connectStart":163.5,"domainLookupEnd":163.5,"domainLookupStart":163.5,"fetchStart":163.5,"redirectEnd":0,"redirectStart":0,"requestStart":173.5,"responseEnd":279.2000000476837,"responseStart":234.70000004768372,"secureConnectionStart":163.5},{"duration":40.90000009536743,"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":163.59999990463257,"connectEnd":163.59999990463257,"connectStart":163.59999990463257,"domainLookupEnd":163.59999990463257,"domainLookupStart":163.59999990463257,"fetchStart":163.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":176.20000004768372,"responseEnd":204.5,"responseStart":203.89999985694885,"secureConnectionStart":163.59999990463257},{"duration":42,"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":163.59999990463257,"connectEnd":163.59999990463257,"connectStart":163.59999990463257,"domainLookupEnd":163.59999990463257,"domainLookupStart":163.59999990463257,"fetchStart":163.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":176.5,"responseEnd":205.59999990463257,"responseStart":205.20000004768372,"secureConnectionStart":163.59999990463257},{"duration":12.599999904632568,"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":163.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":163.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":176.39999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":83.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":163.89999985694885,"connectEnd":163.89999985694885,"connectStart":163.89999985694885,"domainLookupEnd":163.89999985694885,"domainLookupStart":163.89999985694885,"fetchStart":163.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":178.70000004768372,"responseEnd":247.20000004768372,"responseStart":246.5,"secureConnectionStart":163.89999985694885},{"duration":13.200000047683716,"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":164.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":164.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":177.29999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":46.60000014305115,"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":164.09999990463257,"connectEnd":164.09999990463257,"connectStart":164.09999990463257,"domainLookupEnd":164.09999990463257,"domainLookupStart":164.09999990463257,"fetchStart":164.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":179.59999990463257,"responseEnd":210.70000004768372,"responseStart":205.70000004768372,"secureConnectionStart":164.09999990463257},{"duration":30.40000009536743,"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":172.89999985694885,"connectEnd":186.59999990463257,"connectStart":186.59999990463257,"domainLookupEnd":186.59999990463257,"domainLookupStart":186.59999990463257,"fetchStart":172.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":186.79999995231628,"responseEnd":203.29999995231628,"responseStart":199.59999990463257,"secureConnectionStart":186.59999990463257},{"duration":49.200000047683716,"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":173.89999985694885,"connectEnd":173.89999985694885,"connectStart":173.89999985694885,"domainLookupEnd":173.89999985694885,"domainLookupStart":173.89999985694885,"fetchStart":173.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":201.59999990463257,"responseEnd":223.09999990463257,"responseStart":218.59999990463257,"secureConnectionStart":173.89999985694885},{"duration":205.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":466.2000000476837,"connectEnd":466.2000000476837,"connectStart":466.2000000476837,"domainLookupEnd":466.2000000476837,"domainLookupStart":466.2000000476837,"fetchStart":466.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":640.5999999046326,"responseEnd":671.8999998569489,"responseStart":671.2999999523163,"secureConnectionStart":466.2000000476837}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":27,"responseStart":155,"responseEnd":173,"domLoading":159,"domInteractive":808,"domContentLoadedEventStart":808,"domContentLoadedEventEnd":850,"domComplete":1158,"loadEventStart":1159,"loadEventEnd":1159,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":787.2999999523163},{"name":"bigPipe.sidebar-id.end","time":788.2000000476837},{"name":"bigPipe.activity-panel-pipe-id.start","time":788.3999998569489},{"name":"bigPipe.activity-panel-pipe-id.end","time":790},{"name":"activityTabFullyLoaded","time":866.5}],"measures":[],"correlationId":"13781cffdde6f6","effectiveType":"4g","downlink":9,"rtt":0,"serverDuration":74,"dbReadsTimeInMs":11,"dbConnsTimeInMs":17,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This is how it looks like in PostgreSQL. Note the use of CTE (
MDEV-8308)postgres=# SELECT * FROM t1;
id | myarray
----+---------
1 | {1,2,4}
(1 row)
postgres=# SELECT * FROM t2;
id | myarray
----+---------
(0 rows)
postgres=# WITH del_t1 AS (DELETE FROM t1 RETURNING *)
INSERT INTO t2 SELECT * FROM del_t1;
INSERT 0 1
postgres=# SELECT * FROM t1;
id | myarray
----+---------
(0 rows)
postgres=# SELECT * FROM t2;
id | myarray
----+---------
1 | {1,2,4}
(1 row)