@@ -401,8 +401,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
401
401
List * exprList = NIL ;
402
402
bool isGeneralSelect ;
403
403
List * sub_rtable ;
404
- List * sub_relnamespace ;
405
- List * sub_varnamespace ;
404
+ List * sub_namespace ;
406
405
List * icolumns ;
407
406
List * attrnos ;
408
407
RangeTblEntry * rte ;
@@ -454,16 +453,13 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
454
453
{
455
454
sub_rtable = pstate -> p_rtable ;
456
455
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 ;
461
458
}
462
459
else
463
460
{
464
461
sub_rtable = NIL ; /* not used, but keep compiler quiet */
465
- sub_relnamespace = NIL ;
466
- sub_varnamespace = NIL ;
462
+ sub_namespace = NIL ;
467
463
}
468
464
469
465
/*
@@ -513,8 +509,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
513
509
*/
514
510
sub_pstate -> p_rtable = sub_rtable ;
515
511
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 ;
518
513
519
514
selectQuery = transformStmt (sub_pstate , stmt -> selectStmt );
520
515
@@ -751,8 +746,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
751
746
*/
752
747
if (stmt -> returningList )
753
748
{
754
- pstate -> p_relnamespace = NIL ;
755
- pstate -> p_varnamespace = NIL ;
749
+ pstate -> p_namespace = NIL ;
756
750
addRTEtoQuery (pstate , pstate -> p_target_rangetblentry ,
757
751
false, true, true);
758
752
qry -> returningList = transformReturningList (pstate ,
@@ -1305,8 +1299,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
1305
1299
* l ;
1306
1300
List * targetvars ,
1307
1301
* targetnames ,
1308
- * sv_relnamespace ,
1309
- * sv_varnamespace ;
1302
+ * sv_namespace ;
1310
1303
int sv_rtable_length ;
1311
1304
RangeTblEntry * jrte ;
1312
1305
int tllen ;
@@ -1433,7 +1426,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
1433
1426
1434
1427
/*
1435
1428
* 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
1437
1430
* output columns visible. A Join RTE node is handy for this, since we
1438
1431
* can easily control the Vars generated upon matches.
1439
1432
*
@@ -1450,12 +1443,10 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
1450
1443
NULL ,
1451
1444
false);
1452
1445
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 ;
1457
1448
1458
- /* add jrte to varnamespace only */
1449
+ /* add jrte to column namespace only */
1459
1450
addRTEtoQuery (pstate , jrte , false, false, true);
1460
1451
1461
1452
/*
@@ -1472,9 +1463,9 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
1472
1463
false /* no unknowns expected */ ,
1473
1464
false /* allow SQL92 rules */ );
1474
1465
1466
+ /* restore namespace, remove jrte from rtable */
1467
+ pstate -> p_namespace = sv_namespace ;
1475
1468
pstate -> p_rtable = list_truncate (pstate -> p_rtable , sv_rtable_length );
1476
- pstate -> p_relnamespace = sv_relnamespace ;
1477
- pstate -> p_varnamespace = sv_varnamespace ;
1478
1469
1479
1470
if (tllen != list_length (qry -> targetList ))
1480
1471
ereport (ERROR ,
@@ -1595,7 +1586,7 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
1595
1586
* because the namespace will be empty, but it could happen if we are
1596
1587
* inside a rule.
1597
1588
*/
1598
- if (pstate -> p_relnamespace || pstate -> p_varnamespace )
1589
+ if (pstate -> p_namespace )
1599
1590
{
1600
1591
if (contain_vars_of_level ((Node * ) selectQuery , 1 ))
1601
1592
ereport (ERROR ,
0 commit comments