108{
114 List *mergeActionList;
116
117
119
121 qry->hasRecursive = false;
122
123
124 if (
stmt->withClause)
125 {
126 if (
stmt->withClause->recursive)
129 errmsg(
"WITH RECURSIVE is not supported for MERGE statement")));
130
133 }
134
135
136
137
141 foreach(l,
stmt->mergeWhenClauses)
142 {
144
145
146
147
148
149
150
151
153 {
156 break;
159 break;
162 break;
165 break;
166 default:
167 elog(
ERROR,
"unknown action in MERGE WHEN clause");
168 }
169
170
171
172
176 errmsg(
"unreachable WHEN clause specified after unconditional WHEN clause")));
179 }
180
181
182
183
184
185
186
187
188
189
190
191
195 qry->mergeTargetRelation = qry->resultRelation;
196
197
203 errmsg(
"cannot execute MERGE on relation \"%s\"",
206
207
212
213
214
215
216
217
219 nsitem->p_names->aliasname) == 0)
222 errmsg(
"name \"%s\" specified more than once",
224 errdetail(
"The name is used both as MERGE target table and data source."));
225
226
227
228
229
233
234
235
236
237
241
242
243
244
245
246
248
249
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267 mergeActionList =
NIL;
268 foreach(l,
stmt->mergeWhenClauses)
269 {
272
276
277
278
279
280
282 qry->resultRelation,
284
285
286
287
288
289
290
291
294
295
296
297
298 switch (
action->commandType)
299 {
301 {
309
314
316
317
318
319
321 {
322
323
324
325
326
327
329 }
330 else
331 {
332
333
334
335
336
337
338
339
340
341
342
343
347 true);
348
349
353 false);
354 }
355
356
357
358
359
360
363 {
368
372 false);
374
378 }
379 }
380 break;
385 break;
387 break;
388
391 break;
392 default:
393 elog(
ERROR,
"unknown action in MERGE WHEN clause");
394 }
395
396 mergeActionList =
lappend(mergeActionList, action);
397 }
398
400
401 qry->hasTargetSRFs = false;
403
405
406 return qry;
407}
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define Assert(condition)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
List * lappend(List *list, void *datum)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Node * transformWhereClause(ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
void transformFromClause(ParseState *pstate, List *frmList)
int setTargetTable(ParseState *pstate, RangeVar *relation, bool inh, bool alsoSource, AclMode requiredPerms)
void assign_query_collations(ParseState *pstate, Query *query)
List * transformWithClause(ParseState *pstate, WithClause *withClause)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
static void setNamespaceForMergeWhen(ParseState *pstate, MergeWhenClause *mergeWhenClause, Index targetRTI, Index sourceRTI)
@ EXPR_KIND_MERGE_RETURNING
@ EXPR_KIND_VALUES_SINGLE
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
List * checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
List * transformInsertRow(ParseState *pstate, List *exprlist, List *stmtcols, List *icolumns, List *attrnos, bool strip_indirection)
void transformReturningClause(ParseState *pstate, Query *qry, ReturningClause *returningClause, ParseExprKind exprKind)
List * transformUpdateTargetList(ParseState *pstate, List *origTlist)
int errdetail_relkind_not_supported(char relkind)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forthree(cell1, list1, cell2, list2, cell3, list3)
#define NUM_MERGE_MATCH_KINDS
@ MERGE_WHEN_NOT_MATCHED_BY_TARGET
@ MERGE_WHEN_NOT_MATCHED_BY_SOURCE
#define RelationGetRelationName(relation)
RTEPermissionInfo * p_perminfo
ParseNamespaceItem * p_target_nsitem
Relation p_target_relation
Node * mergeJoinCondition
#define FirstLowInvalidHeapAttributeNumber