@@ -114,8 +114,9 @@ static Node *transformXmlSerialize(ParseState *pstate, XmlSerialize *xs);
114
114
static Node * transformBooleanTest (ParseState * pstate , BooleanTest * b );
115
115
static Node * transformCurrentOfExpr (ParseState * pstate , CurrentOfExpr * cexpr );
116
116
static Node * transformColumnRef (ParseState * pstate , ColumnRef * cref );
117
- static Node * transformWholeRowRef (ParseState * pstate , RangeTblEntry * rte ,
118
- int location );
117
+ static Node * transformWholeRowRef (ParseState * pstate ,
118
+ ParseNamespaceItem * nsitem ,
119
+ int sublevels_up , int location );
119
120
static Node * transformIndirection (ParseState * pstate , A_Indirection * ind );
120
121
static Node * transformTypeCast (ParseState * pstate , TypeCast * tc );
121
122
static Node * transformCollateClause (ParseState * pstate , CollateClause * c );
@@ -510,7 +511,7 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
510
511
char * nspname = NULL ;
511
512
char * relname = NULL ;
512
513
char * colname = NULL ;
513
- RangeTblEntry * rte ;
514
+ ParseNamespaceItem * nsitem ;
514
515
int levels_up ;
515
516
enum
516
517
{
@@ -653,11 +654,11 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
653
654
* PostQUEL-inspired syntax. The preferred form now is
654
655
* "rel.*".
655
656
*/
656
- rte = refnameRangeTblEntry (pstate , NULL , colname ,
657
- cref -> location ,
658
- & levels_up );
659
- if (rte )
660
- node = transformWholeRowRef (pstate , rte ,
657
+ nsitem = refnameNamespaceItem (pstate , NULL , colname ,
658
+ cref -> location ,
659
+ & levels_up );
660
+ if (nsitem )
661
+ node = transformWholeRowRef (pstate , nsitem , levels_up ,
661
662
cref -> location );
662
663
}
663
664
break ;
@@ -670,11 +671,11 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
670
671
Assert (IsA (field1 , String ));
671
672
relname = strVal (field1 );
672
673
673
- /* Locate the referenced RTE */
674
- rte = refnameRangeTblEntry (pstate , nspname , relname ,
675
- cref -> location ,
676
- & levels_up );
677
- if (rte == NULL )
674
+ /* Locate the referenced nsitem */
675
+ nsitem = refnameNamespaceItem (pstate , nspname , relname ,
676
+ cref -> location ,
677
+ & levels_up );
678
+ if (nsitem == NULL )
678
679
{
679
680
crerr = CRERR_NO_RTE ;
680
681
break ;
@@ -683,20 +684,22 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
683
684
/* Whole-row reference? */
684
685
if (IsA (field2 , A_Star ))
685
686
{
686
- node = transformWholeRowRef (pstate , rte , cref -> location );
687
+ node = transformWholeRowRef (pstate , nsitem , levels_up ,
688
+ cref -> location );
687
689
break ;
688
690
}
689
691
690
692
Assert (IsA (field2 , String ));
691
693
colname = strVal (field2 );
692
694
693
- /* Try to identify as a column of the RTE */
694
- node = scanRTEForColumn (pstate , rte , colname , cref -> location ,
695
- 0 , NULL );
695
+ /* Try to identify as a column of the nsitem */
696
+ node = scanNSItemForColumn (pstate , nsitem , levels_up , colname ,
697
+ cref -> location );
696
698
if (node == NULL )
697
699
{
698
700
/* Try it as a function call on the whole row */
699
- node = transformWholeRowRef (pstate , rte , cref -> location );
701
+ node = transformWholeRowRef (pstate , nsitem , levels_up ,
702
+ cref -> location );
700
703
node = ParseFuncOrColumn (pstate ,
701
704
list_make1 (makeString (colname )),
702
705
list_make1 (node ),
@@ -718,11 +721,11 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
718
721
Assert (IsA (field2 , String ));
719
722
relname = strVal (field2 );
720
723
721
- /* Locate the referenced RTE */
722
- rte = refnameRangeTblEntry (pstate , nspname , relname ,
723
- cref -> location ,
724
- & levels_up );
725
- if (rte == NULL )
724
+ /* Locate the referenced nsitem */
725
+ nsitem = refnameNamespaceItem (pstate , nspname , relname ,
726
+ cref -> location ,
727
+ & levels_up );
728
+ if (nsitem == NULL )
726
729
{
727
730
crerr = CRERR_NO_RTE ;
728
731
break ;
@@ -731,20 +734,22 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
731
734
/* Whole-row reference? */
732
735
if (IsA (field3 , A_Star ))
733
736
{
734
- node = transformWholeRowRef (pstate , rte , cref -> location );
737
+ node = transformWholeRowRef (pstate , nsitem , levels_up ,
738
+ cref -> location );
735
739
break ;
736
740
}
737
741
738
742
Assert (IsA (field3 , String ));
739
743
colname = strVal (field3 );
740
744
741
- /* Try to identify as a column of the RTE */
742
- node = scanRTEForColumn (pstate , rte , colname , cref -> location ,
743
- 0 , NULL );
745
+ /* Try to identify as a column of the nsitem */
746
+ node = scanNSItemForColumn (pstate , nsitem , levels_up , colname ,
747
+ cref -> location );
744
748
if (node == NULL )
745
749
{
746
750
/* Try it as a function call on the whole row */
747
- node = transformWholeRowRef (pstate , rte , cref -> location );
751
+ node = transformWholeRowRef (pstate , nsitem , levels_up ,
752
+ cref -> location );
748
753
node = ParseFuncOrColumn (pstate ,
749
754
list_make1 (makeString (colname )),
750
755
list_make1 (node ),
@@ -779,11 +784,11 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
779
784
break ;
780
785
}
781
786
782
- /* Locate the referenced RTE */
783
- rte = refnameRangeTblEntry (pstate , nspname , relname ,
784
- cref -> location ,
785
- & levels_up );
786
- if (rte == NULL )
787
+ /* Locate the referenced nsitem */
788
+ nsitem = refnameNamespaceItem (pstate , nspname , relname ,
789
+ cref -> location ,
790
+ & levels_up );
791
+ if (nsitem == NULL )
787
792
{
788
793
crerr = CRERR_NO_RTE ;
789
794
break ;
@@ -792,20 +797,22 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref)
792
797
/* Whole-row reference? */
793
798
if (IsA (field4 , A_Star ))
794
799
{
795
- node = transformWholeRowRef (pstate , rte , cref -> location );
800
+ node = transformWholeRowRef (pstate , nsitem , levels_up ,
801
+ cref -> location );
796
802
break ;
797
803
}
798
804
799
805
Assert (IsA (field4 , String ));
800
806
colname = strVal (field4 );
801
807
802
- /* Try to identify as a column of the RTE */
803
- node = scanRTEForColumn (pstate , rte , colname , cref -> location ,
804
- 0 , NULL );
808
+ /* Try to identify as a column of the nsitem */
809
+ node = scanNSItemForColumn (pstate , nsitem , levels_up , colname ,
810
+ cref -> location );
805
811
if (node == NULL )
806
812
{
807
813
/* Try it as a function call on the whole row */
808
- node = transformWholeRowRef (pstate , rte , cref -> location );
814
+ node = transformWholeRowRef (pstate , nsitem , levels_up ,
815
+ cref -> location );
809
816
node = ParseFuncOrColumn (pstate ,
810
817
list_make1 (makeString (colname )),
811
818
list_make1 (node ),
@@ -2648,14 +2655,9 @@ transformBooleanTest(ParseState *pstate, BooleanTest *b)
2648
2655
static Node *
2649
2656
transformCurrentOfExpr (ParseState * pstate , CurrentOfExpr * cexpr )
2650
2657
{
2651
- int sublevels_up ;
2652
-
2653
2658
/* CURRENT OF can only appear at top level of UPDATE/DELETE */
2654
- Assert (pstate -> p_target_rangetblentry != NULL );
2655
- cexpr -> cvarno = RTERangeTablePosn (pstate ,
2656
- pstate -> p_target_rangetblentry ,
2657
- & sublevels_up );
2658
- Assert (sublevels_up == 0 );
2659
+ Assert (pstate -> p_target_rtindex > 0 );
2660
+ cexpr -> cvarno = pstate -> p_target_rtindex ;
2659
2661
2660
2662
/*
2661
2663
* Check to see if the cursor name matches a parameter of type REFCURSOR.
@@ -2703,14 +2705,10 @@ transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr)
2703
2705
* Construct a whole-row reference to represent the notation "relation.*".
2704
2706
*/
2705
2707
static Node *
2706
- transformWholeRowRef (ParseState * pstate , RangeTblEntry * rte , int location )
2708
+ transformWholeRowRef (ParseState * pstate , ParseNamespaceItem * nsitem ,
2709
+ int sublevels_up , int location )
2707
2710
{
2708
2711
Var * result ;
2709
- int vnum ;
2710
- int sublevels_up ;
2711
-
2712
- /* Find the RTE's rangetable location */
2713
- vnum = RTERangeTablePosn (pstate , rte , & sublevels_up );
2714
2712
2715
2713
/*
2716
2714
* Build the appropriate referencing node. Note that if the RTE is a
@@ -2720,13 +2718,14 @@ transformWholeRowRef(ParseState *pstate, RangeTblEntry *rte, int location)
2720
2718
* historically. One argument for it is that "rel" and "rel.*" mean the
2721
2719
* same thing for composite relations, so why not for scalar functions...
2722
2720
*/
2723
- result = makeWholeRowVar (rte , vnum , sublevels_up , true);
2721
+ result = makeWholeRowVar (nsitem -> p_rte , nsitem -> p_rtindex ,
2722
+ sublevels_up , true);
2724
2723
2725
2724
/* location is not filled in by makeWholeRowVar */
2726
2725
result -> location = location ;
2727
2726
2728
2727
/* mark relation as requiring whole-row SELECT access */
2729
- markVarForSelectPriv (pstate , result , rte );
2728
+ markVarForSelectPriv (pstate , result , nsitem -> p_rte );
2730
2729
2731
2730
return (Node * ) result ;
2732
2731
}
0 commit comments