@@ -401,8 +401,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
401401 List * exprList = NIL ;
402402 bool isGeneralSelect ;
403403 List * sub_rtable ;
404- List * sub_relnamespace ;
405- List * sub_varnamespace ;
404+ List * sub_namespace ;
406405 List * icolumns ;
407406 List * attrnos ;
408407 RangeTblEntry * rte ;
@@ -454,16 +453,13 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
454453 {
455454 sub_rtable = pstate -> p_rtable ;
456455 pstate -> 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 }
462459 else
463460 {
464461 sub_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 */
514510 sub_pstate -> p_rtable = sub_rtable ;
515511 sub_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
519514 selectQuery = transformStmt (sub_pstate , stmt -> selectStmt );
520515
@@ -751,8 +746,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
751746 */
752747 if (stmt -> returningList )
753748 {
754- pstate -> p_relnamespace = NIL ;
755- pstate -> p_varnamespace = NIL ;
749+ pstate -> p_namespace = NIL ;
756750 addRTEtoQuery (pstate , pstate -> p_target_rangetblentry ,
757751 false, true, true);
758752 qry -> returningList = transformReturningList (pstate ,
@@ -1305,8 +1299,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
13051299 * l ;
13061300 List * targetvars ,
13071301 * targetnames ,
1308- * sv_relnamespace ,
1309- * sv_varnamespace ;
1302+ * sv_namespace ;
13101303 int sv_rtable_length ;
13111304 RangeTblEntry * jrte ;
13121305 int 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 a varnamespace entry that makes the
1429+ * using the output columns, generate a namespace 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)
14501443 NULL ,
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 to varnamespace only */
1449+ /* add jrte to column namespace only */
14591450 addRTEtoQuery (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 ;
14751468 pstate -> p_rtable = list_truncate (pstate -> p_rtable , sv_rtable_length );
1476- pstate -> p_relnamespace = sv_relnamespace ;
1477- pstate -> p_varnamespace = sv_varnamespace ;
14781469
14791470 if (tllen != list_length (qry -> targetList ))
14801471 ereport (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 {
16001591 if (contain_vars_of_level ((Node * ) selectQuery , 1 ))
16011592 ereport (ERROR ,
0 commit comments