mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
Add OLD/NEW support to RETURNING in DML queries.
This allows the RETURNING list of INSERT/UPDATE/DELETE/MERGE queries to explicitly return old and new values by using the special aliases "old" and "new", which are automatically added to the query (if not already defined) while parsing its RETURNING list, allowing things like: RETURNING old.colname, new.colname, ... RETURNING old.*, new.* Additionally, a new syntax is supported, allowing the names "old" and "new" to be changed to user-supplied alias names, e.g.: RETURNING WITH (OLD AS o, NEW AS n) o.colname, n.colname, ... This is useful when the names "old" and "new" are already defined, such as inside trigger functions, allowing backwards compatibility to be maintained -- the interpretation of any existing queries that happen to already refer to relations called "old" or "new", or use those as aliases for other relations, is not changed. For an INSERT, old values will generally be NULL, and for a DELETE, new values will generally be NULL, but that may change for an INSERT with an ON CONFLICT ... DO UPDATE clause, or if a query rewrite rule changes the command type. Therefore, we put no restrictions on the use of old and new in any DML queries. Dean Rasheed, reviewed by Jian He and Jeff Davis. Discussion: https://postgr.es/m/CAEZATCWx0J0-v=Qjc6gXzR=KtsdvAE7Ow=D=mu50AgOe+pvisQ@mail.gmail.com
This commit is contained in:
@@ -105,8 +105,8 @@ my %replace_line = (
|
||||
'SHOW TRANSACTION ISOLATION LEVEL ecpg_into',
|
||||
'VariableShowStmt SHOW SESSION AUTHORIZATION' =>
|
||||
'SHOW SESSION AUTHORIZATION ecpg_into',
|
||||
'returning_clause RETURNING target_list' =>
|
||||
'RETURNING target_list opt_ecpg_into',
|
||||
'returning_clause RETURNING returning_with_clause target_list' =>
|
||||
'RETURNING returning_with_clause target_list opt_ecpg_into',
|
||||
'ExecuteStmt EXECUTE name execute_param_clause' =>
|
||||
'EXECUTE prepared_name execute_param_clause execute_rest',
|
||||
'ExecuteStmt CREATE OptTemp TABLE create_as_target AS EXECUTE name execute_param_clause opt_with_data'
|
||||
|
||||
Reference in New Issue
Block a user