mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
WITH support in MERGE
Author: Peter Geoghegan Recursive support removed, no tests Docs added by me
This commit is contained in:
@@ -3055,6 +3055,7 @@ _copyMergeStmt(const MergeStmt *from)
|
||||
COPY_NODE_FIELD(source_relation);
|
||||
COPY_NODE_FIELD(join_condition);
|
||||
COPY_NODE_FIELD(mergeActionList);
|
||||
COPY_NODE_FIELD(withClause);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
@@ -1051,6 +1051,7 @@ _equalMergeStmt(const MergeStmt *a, const MergeStmt *b)
|
||||
COMPARE_NODE_FIELD(source_relation);
|
||||
COMPARE_NODE_FIELD(join_condition);
|
||||
COMPARE_NODE_FIELD(mergeActionList);
|
||||
COMPARE_NODE_FIELD(withClause);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3446,6 +3446,8 @@ raw_expression_tree_walker(Node *node,
|
||||
return true;
|
||||
if (walker(stmt->mergeActionList, context))
|
||||
return true;
|
||||
if (walker(stmt->withClause, context))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case T_MergeAction:
|
||||
|
||||
@@ -11105,17 +11105,18 @@ set_target_list:
|
||||
*****************************************************************************/
|
||||
|
||||
MergeStmt:
|
||||
MERGE INTO relation_expr_opt_alias
|
||||
opt_with_clause MERGE INTO relation_expr_opt_alias
|
||||
USING table_ref
|
||||
ON a_expr
|
||||
merge_when_list
|
||||
{
|
||||
MergeStmt *m = makeNode(MergeStmt);
|
||||
|
||||
m->relation = $3;
|
||||
m->source_relation = $5;
|
||||
m->join_condition = $7;
|
||||
m->mergeActionList = $8;
|
||||
m->withClause = $1;
|
||||
m->relation = $4;
|
||||
m->source_relation = $6;
|
||||
m->join_condition = $8;
|
||||
m->mergeActionList = $9;
|
||||
|
||||
$$ = (Node *)m;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "parser/parsetree.h"
|
||||
#include "parser/parser.h"
|
||||
#include "parser/parse_clause.h"
|
||||
#include "parser/parse_cte.h"
|
||||
#include "parser/parse_merge.h"
|
||||
#include "parser/parse_relation.h"
|
||||
#include "parser/parse_target.h"
|
||||
@@ -202,6 +203,19 @@ transformMergeStmt(ParseState *pstate, MergeStmt *stmt)
|
||||
Assert(pstate->p_ctenamespace == NIL);
|
||||
|
||||
qry->commandType = CMD_MERGE;
|
||||
qry->hasRecursive = false;
|
||||
|
||||
/* process the WITH clause independently of all else */
|
||||
if (stmt->withClause)
|
||||
{
|
||||
if (stmt->withClause->recursive)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("WITH RECURSIVE is not supported for MERGE statement")));
|
||||
|
||||
qry->cteList = transformWithClause(pstate, stmt->withClause);
|
||||
qry->hasModifyingCTE = pstate->p_hasModifyingCTE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check WHEN clauses for permissions and sanity
|
||||
|
||||
Reference in New Issue
Block a user