*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.312 2009/10/28 17:36:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.313 2009/10/28 18:51:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
push_plan(deparse_namespace *dpns, Plan *subplan)
{
/*
- * We special-case ModifyTable to pretend that the first child plan is the
- * OUTER referent; otherwise normal. This is to support RETURNING lists
- * containing references to non-target relations.
+ * We special-case Append to pretend that the first child plan is the
+ * OUTER referent; we have to interpret OUTER Vars in the Append's tlist
+ * according to one of the children, and the first one is the most
+ * natural choice. Likewise special-case ModifyTable to pretend that the
+ * first child plan is the OUTER referent; this is to support RETURNING
+ * lists containing references to non-target relations.
*/
- if (IsA(subplan, ModifyTable))
+ if (IsA(subplan, Append))
+ dpns->outer_plan = (Plan *) linitial(((Append *) subplan)->appendplans);
+ else if (IsA(subplan, ModifyTable))
dpns->outer_plan = (Plan *) linitial(((ModifyTable *) subplan)->plans);
else
dpns->outer_plan = outerPlan(subplan);