@@ -401,8 +401,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
401401List * exprList = NIL ;
402402bool isGeneralSelect ;
403403List * sub_rtable ;
404- List * sub_relnamespace ;
405- List * sub_varnamespace ;
404+ List * sub_namespace ;
406405List * icolumns ;
407406List * attrnos ;
408407RangeTblEntry * rte ;
@@ -454,16 +453,13 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
454453{
455454sub_rtable = pstate -> p_rtable ;
456455pstate -> p_rtable = NIL ;
457- sub_relnamespace = pstate -> p_relnamespace ;
458- pstate -> p_relnamespace = NIL ;
459- sub_varnamespace = pstate -> p_varnamespace ;
460- pstate -> p_varnamespace = NIL ;
456+ sub_namespace = pstate -> p_namespace ;
457+ pstate -> p_namespace = NIL ;
461458}
462459else
463460{
464461sub_rtable = NIL ;/* not used, but keep compiler quiet */
465- sub_relnamespace = NIL ;
466- sub_varnamespace = NIL ;
462+ sub_namespace = NIL ;
467463}
468464
469465/*
@@ -513,8 +509,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
513509 */
514510sub_pstate -> p_rtable = sub_rtable ;
515511sub_pstate -> p_joinexprs = NIL ;/* sub_rtable has no joins */
516- sub_pstate -> p_relnamespace = sub_relnamespace ;
517- sub_pstate -> p_varnamespace = sub_varnamespace ;
512+ sub_pstate -> p_namespace = sub_namespace ;
518513
519514selectQuery = transformStmt (sub_pstate ,stmt -> selectStmt );
520515
@@ -751,8 +746,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
751746 */
752747if (stmt -> returningList )
753748{
754- pstate -> p_relnamespace = NIL ;
755- pstate -> p_varnamespace = NIL ;
749+ pstate -> p_namespace = NIL ;
756750addRTEtoQuery (pstate ,pstate -> p_target_rangetblentry ,
757751 false, true, true);
758752qry -> returningList = transformReturningList (pstate ,
@@ -1305,8 +1299,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
13051299* l ;
13061300List * targetvars ,
13071301* targetnames ,
1308- * sv_relnamespace ,
1309- * sv_varnamespace ;
1302+ * sv_namespace ;
13101303int sv_rtable_length ;
13111304RangeTblEntry * jrte ;
13121305int tllen ;
@@ -1433,7 +1426,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
14331426
14341427/*
14351428 * As a first step towards supporting sort clauses that are expressions
1436- * using the output columns, generate avarnamespace entry that makes the
1429+ * using the output columns, generate anamespace entry that makes the
14371430 * output columns visible.A Join RTE node is handy for this, since we
14381431 * can easily control the Vars generated upon matches.
14391432 *
@@ -1450,12 +1443,10 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
14501443NULL ,
14511444 false);
14521445
1453- sv_relnamespace = pstate -> p_relnamespace ;
1454- sv_varnamespace = pstate -> p_varnamespace ;
1455- pstate -> p_relnamespace = NIL ;
1456- pstate -> p_varnamespace = NIL ;
1446+ sv_namespace = pstate -> p_namespace ;
1447+ pstate -> p_namespace = NIL ;
14571448
1458- /* add jrte tovarnamespace only */
1449+ /* add jrte tocolumn namespace only */
14591450addRTEtoQuery (pstate ,jrte , false, false, true);
14601451
14611452/*
@@ -1472,9 +1463,9 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
14721463 false/* no unknowns expected */ ,
14731464 false/* allow SQL92 rules */ );
14741465
1466+ /* restore namespace, remove jrte from rtable */
1467+ pstate -> p_namespace = sv_namespace ;
14751468pstate -> p_rtable = list_truncate (pstate -> p_rtable ,sv_rtable_length );
1476- pstate -> p_relnamespace = sv_relnamespace ;
1477- pstate -> p_varnamespace = sv_varnamespace ;
14781469
14791470if (tllen != list_length (qry -> targetList ))
14801471ereport (ERROR ,
@@ -1595,7 +1586,7 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
15951586 * because the namespace will be empty, but it could happen if we are
15961587 * inside a rule.
15971588 */
1598- if (pstate -> p_relnamespace || pstate -> p_varnamespace )
1589+ if (pstate -> p_namespace )
15991590{
16001591if (contain_vars_of_level ((Node * )selectQuery ,1 ))
16011592ereport (ERROR ,