Skip to content

Latest commit

 

History

History
76 lines (48 loc) · 3.73 KB

20240318_02.md

File metadata and controls

76 lines (48 loc) · 3.73 KB

PostgreSQL 17 preview - Add RETURNING support to MERGE

作者

digoal

日期

2024-03-18

标签

PostgreSQL , PolarDB , DuckDB , merge , returning


背景

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=c649fa24a42ba89bf5460c7110e4fc8eeca65959

Add RETURNING support to MERGE.  
  
author	Dean Rasheed <dean.a.rasheed@gmail.com>	  
Sun, 17 Mar 2024 13:58:59 +0000 (13:58 +0000)  
committer	Dean Rasheed <dean.a.rasheed@gmail.com>	  
Sun, 17 Mar 2024 13:58:59 +0000 (13:58 +0000)  
commit	c649fa24a42ba89bf5460c7110e4fc8eeca65959  
tree	de7d51489c6c6fff56fddad66c0ced2aa427d6a5	tree  
parent	6a004f1be87d34cfe51acf2fe2552d2b08a79273	commit | diff  
Add RETURNING support to MERGE.  
  
This allows a RETURNING clause to be appended to a MERGE query, to  
return values based on each row inserted, updated, or deleted. As with  
plain INSERT, UPDATE, and DELETE commands, the returned values are  
based on the new contents of the target table for INSERT and UPDATE  
actions, and on its old contents for DELETE actions. Values from the  
source relation may also be returned.  
  
As with INSERT/UPDATE/DELETE, the output of MERGE ... RETURNING may be  
used as the source relation for other operations such as WITH queries  
and COPY commands.  
  
Additionally, a special function merge_action() is provided, which  
returns 'INSERT', 'UPDATE', or 'DELETE', depending on the action  
executed for each row. The merge_action() function can be used  
anywhere in the RETURNING list, including in arbitrary expressions and  
subqueries, but it is an error to use it anywhere outside of a MERGE  
query's RETURNING list.  
  
Dean Rasheed, reviewed by Isaac Morland, Vik Fearing, Alvaro Herrera,  
Gurjeet Singh, Jian He, Jeff Davis, Merlin Moncure, Peter Eisentraut,  
and Wolfgang Walther.  
  
Discussion: http://postgr.es/m/CAEZATCWePEGQR5LBn-vD6SfeLZafzEm2Qy_L_Oky2=qw2w3Pzg@mail.gmail.com  

digoal's wechat