mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 10:30:33 +03:00 
			
		
		
		
	WITH support in MERGE
Author: Peter Geoghegan Recursive support removed, no tests Docs added by me
This commit is contained in:
		| @@ -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