On Fri, 15 Mar 2024 at 11:06, Dean Rasheed <dean.a.rash...@gmail.com> wrote: > > Updated patch attached. >
I have gone over this patch again in detail, and I believe that the code is in good shape. All review comments have been addressed, and the only thing remaining is the syntax question. To recap, this adds support for a single RETURNING list at the end of a MERGE command, and a special MERGE_ACTION() function that may be used in the RETURNING list to return the action command string ('INSERT', 'UPDATE', or 'DELETE') that was executed. Looking for similar precedents in other databases, SQL Server uses a slightly different (non-standard) syntax for MERGE, and uses "OUTPUT" instead of "RETURNING" to return rows. But it does allow "$action" in the output list, which is functionally equivalent to MERGE_ACTION(): https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver16#output_clause In the future, we may choose to support the SQL standard syntax for returning rows modified by INSERT, UPDATE, DELETE, and MERGE commands, but I don't think that this patch needs to do that. What this patch does is to make MERGE more consistent with INSERT, UPDATE, and DELETE, by allowing RETURNING. And if the patch to add support for returning OLD/NEW values [1] makes it in too, it will be more powerful than the SQL standard syntax, since it will allow both old and new values to be returned at the same time, in arbitrary expressions. So barring any further objections, I'd like to go ahead and get this patch committed. Regards, Dean [1] https://www.postgresql.org/message-id/flat/CAEZATCWx0J0-v=Qjc6gXzR=KtsdvAE7Ow=D=mu50agoe+pv...@mail.gmail.com