[MDEV-5092] Implement UPDATE with result set Created: 2013-10-02  Updated: 2023-12-22

Status: In Review
Project: MariaDB Server
Component/s: Data Manipulation - Update
Fix Version/s: 11.5

Type: New Feature Priority: Major
Reporter: Heinz Wiesinger Assignee: Daniel Black
Resolution: Unresolved Votes: 15
Labels: gsoc17, gsoc18, gsoc19, performance

Issue Links:
Blocks
blocks MDEV-12326 Implement multiple-table UPDATE/DELET... Open
Duplicate
duplicates MDEV-19093 [Feature] Issue #48 SELECT...FROM UPDATE Closed
Relates
relates to MDEV-30737 REPLACE...RETURNING should provide ac... Open
relates to MDEV-3814 Implement DELETE with result set (mwl... Closed
relates to MDEV-10422 INSERT RETURNING Closed
relates to MDEV-12326 Implement multiple-table UPDATE/DELET... Open
relates to MDEV-20033 sql_mode="oracle" does not support IN... Closed

 Description   

Add an UPDATE operation that returns a result set of the changed rows to the client.

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]
RETURNING select_expr [, select_expr ...]

I'm not exactly sure how the corresponding multiple-table syntax should look like, or if it is possible at all. But already having it for single-table updates would be a nice feature.



 Comments   
Comment by Guangpu Feng [ 2014-04-23 ]

I have implemented a similar feature based on Perconar server 5.5.18, the syntax is:

SELECT
select_expr [, select_expr ...]
FROM UPDATE
[LOW_PRIORITY] [IGNORE]
[TARGET_AFFECT_ROW num]
tbl_name
SET col_name1=

{expr1|DEFAULT}

[, col_name2=

{expr2|DEFAULT}

] ... [WHERE where_condition] [ORDER BY ...] [LIMIT row_count]

for short: SELECT...FROM UPDATE...

I know that Oracle and PostgreSQL use the RETURNING syntax, but for MySQL(Oracle/Percona version) that requires JDBC to make some changes, which will
cause compatibility problems

Comment by Guangpu Feng [ 2014-04-23 ]

more detail about "SELECT...FROM...UPDATE", please refer to: https://bugs.launchpad.net/percona-server/+bug/1311471

Comment by Vicențiu Ciorbaru [ 2018-03-23 ]

Hi akhilseshan yes, every task labeled as gsoc18 is available. Feel free to ask any questions you have in this issue tracker and submit your proposal with an implementation plan for it.

Comment by rajiv nayan [ 2019-02-27 ]

hi Igor Babaev

I'm Rajiv Nayan, a third year undergraduate in Computer science at AIETM college Jaipur , India. I would like do this project for GSoC 2018. It would be greatly appreciated if you could help me get started.

Comment by sahaj jain [ 2019-03-03 ]

hello i am sahaj jain from Delhi Technological University, I am familiar with the topics associated with this project and would be happy to take it as my gsoc project. Mentors can mail me at ssaahhaajj@gmail.com to discuss details as i cant find yours here

Comment by Igor Babaev [ 2019-03-05 ]

Hi Rajiv,
You probably meant GSoC 2019
Anyway first of all I need your email address.

Comment by Vicențiu Ciorbaru [ 2019-03-25 ]

ssaahhaajj We encourage students to email questions to the dev mailing list.

I suggest you fire and email to maria-developers mailing list.

https://launchpad.net/~maria-developers

With all your questions. That way the answers are available for everyone. Alternatively, you can post your questions on the JIRA task too, but the developers mailing list has more eyes watching it.

Comment by Anel Husakovic [ 2019-04-01 ]

Ali patch: https://github.com/alibaba/AliSQL/commit/4f246a8450bbf832178abff80e0fbcafd4068b71

Comment by Jeff Gullett (Inactive) [ 2020-03-06 ]

In addition to the proposed implementation to return new values, I would also like this to include the ability to return the old values as well. Something like:

UPDATE table SET col1 = val1 RETURNING old.col1 AS oldCol1Val, new.col1 as newCol1Val;

Comment by Federico Razzoli [ 2020-08-13 ]

+1 for NEW.col and OLD.col.

But then, notice that this should also be added to INSERT ON DUPLICATE KEY UPDATE and REPLACE, both for consistency and because it's useful.

Generated at Thu Feb 08 07:01:36 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.