72 targetRelRTE,
true,
true);
74 sourceRelRTE,
true,
true);
85 targetRelRTE,
false,
false);
87 sourceRelRTE,
true,
true);
103 List *mergeActionList;
111 qry->hasRecursive =
false;
114 if (
stmt->withClause)
116 if (
stmt->withClause->recursive)
118 (
errcode(ERRCODE_SYNTAX_ERROR),
119 errmsg(
"WITH RECURSIVE is not supported for MERGE statement")));
128 is_terminal[0] =
false;
129 is_terminal[1] =
false;
130 foreach(l,
stmt->mergeWhenClauses)
133 int when_type = (mergeWhenClause->
matched ? 0 : 1);
152 elog(
ERROR,
"unknown action in MERGE WHEN clause");
158 if (is_terminal[when_type])
160 (
errcode(ERRCODE_SYNTAX_ERROR),
161 errmsg(
"unreachable WHEN clause specified after unconditional WHEN clause")));
163 is_terminal[when_type] =
true;
181 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
182 errmsg(
"cannot execute MERGE on relation \"%s\"",
188 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
189 errmsg(
"cannot execute MERGE on relation \"%s\"",
191 errdetail(
"MERGE is not supported for relations with rules.")));
207 errcode(ERRCODE_DUPLICATE_ALIAS),
208 errmsg(
"name \"%s\" specified more than once",
210 errdetail(
"The name is used both as MERGE target table and data source."));
250 mergeActionList =
NIL;
251 foreach(l,
stmt->mergeWhenClauses)
262 qry->mergeUseOuterJoin =
true;
285 switch (
action->commandType)
351 forthree(lc, exprList, icols, icolumns, attnos, attrnos)
385 elog(
ERROR,
"unknown action in MERGE WHEN clause");
396 qry->hasTargetSRFs =
false;
411 foreach(lc,
namespace)
415 if (nsitem->
p_rte == rte)
Bitmapset * bms_add_member(Bitmapset *a, int x)
elog(ERROR, "%s: %s", p2, msg)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
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)
Query * transformMergeStmt(ParseState *pstate, MergeStmt *stmt)
static void setNamespaceVisibilityForRTE(List *namespace, RangeTblEntry *rte, bool rel_visible, bool cols_visible)
@ 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 * checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
List * transformUpdateTargetList(ParseState *pstate, List *origTlist)
List * transformInsertRow(ParseState *pstate, List *exprlist, List *stmtcols, List *icolumns, List *attrnos, bool strip_indirection)
#define rt_fetch(rangetable_index, rangetable)
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 RelationGetRelationName(relation)
RTEPermissionInfo * p_perminfo
ParseNamespaceItem * p_target_nsitem
Relation p_target_relation
#define FirstLowInvalidHeapAttributeNumber