mirror of
https://github.com/postgres/postgres.git
synced 2026-01-29 12:02:15 +03:00
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
This commit is contained in:
@@ -243,6 +243,7 @@ typedef enum ExprEvalOp
|
||||
EEOP_AGGREF,
|
||||
EEOP_GROUPING_FUNC,
|
||||
EEOP_WINDOW_FUNC,
|
||||
EEOP_MERGE_SUPPORT_FUNC,
|
||||
EEOP_SUBPLAN,
|
||||
|
||||
/* aggregation related nodes */
|
||||
@@ -810,6 +811,8 @@ extern void ExecEvalJsonConstructor(ExprState *state, ExprEvalStep *op,
|
||||
ExprContext *econtext);
|
||||
extern void ExecEvalJsonIsPredicate(ExprState *state, ExprEvalStep *op);
|
||||
extern void ExecEvalGroupingFunc(ExprState *state, ExprEvalStep *op);
|
||||
extern void ExecEvalMergeSupportFunc(ExprState *state, ExprEvalStep *op,
|
||||
ExprContext *econtext);
|
||||
extern void ExecEvalSubPlan(ExprState *state, ExprEvalStep *op,
|
||||
ExprContext *econtext);
|
||||
extern void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op,
|
||||
|
||||
@@ -97,6 +97,7 @@ typedef struct _SPI_plan *SPIPlanPtr;
|
||||
#define SPI_OK_REL_UNREGISTER 16
|
||||
#define SPI_OK_TD_REGISTER 17
|
||||
#define SPI_OK_MERGE 18
|
||||
#define SPI_OK_MERGE_RETURNING 19
|
||||
|
||||
#define SPI_OPT_NONATOMIC (1 << 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user