summaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/deparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/postgres_fdw/deparse.c')
-rw-r--r--contrib/postgres_fdw/deparse.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c
index 6faf499f9a..5aa3455e30 100644
--- a/contrib/postgres_fdw/deparse.c
+++ b/contrib/postgres_fdw/deparse.c
@@ -1275,7 +1275,7 @@ deparseLockingClause(deparse_expr_cxt *context)
* that DECLARE CURSOR ... FOR UPDATE is supported, which it isn't
* before 8.3.
*/
- if (relid == root->parse->resultRelation &&
+ if (bms_is_member(relid, root->all_result_relids) &&
(root->parse->commandType == CMD_UPDATE ||
root->parse->commandType == CMD_DELETE))
{
@@ -1867,6 +1867,7 @@ deparseUpdateSql(StringInfo buf, RangeTblEntry *rte,
* 'foreignrel' is the RelOptInfo for the target relation or the join relation
* containing all base relations in the query
* 'targetlist' is the tlist of the underlying foreign-scan plan node
+ * (note that this only contains new-value expressions and junk attrs)
* 'targetAttrs' is the target columns of the UPDATE
* 'remote_conds' is the qual clauses that must be evaluated remotely
* '*params_list' is an output list of exprs that will become remote Params
@@ -1888,8 +1889,9 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
deparse_expr_cxt context;
int nestlevel;
bool first;
- ListCell *lc;
RangeTblEntry *rte = planner_rt_fetch(rtindex, root);
+ ListCell *lc,
+ *lc2;
/* Set up context struct for recursion */
context.root = root;
@@ -1908,14 +1910,13 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
nestlevel = set_transmission_modes();
first = true;
- foreach(lc, targetAttrs)
+ forboth(lc, targetlist, lc2, targetAttrs)
{
- int attnum = lfirst_int(lc);
- TargetEntry *tle = get_tle_by_resno(targetlist, attnum);
+ TargetEntry *tle = lfirst_node(TargetEntry, lc);
+ int attnum = lfirst_int(lc2);
- if (!tle)
- elog(ERROR, "attribute number %d not found in UPDATE targetlist",
- attnum);
+ /* update's new-value expressions shouldn't be resjunk */
+ Assert(!tle->resjunk);
if (!first)
appendStringInfoString(buf, ", ");