Skip to content

Commit dd03129

Browse files
committed
UNION select in a CREATE RULE caused a weird error, because transformRuleStmt
got confused by 'dummy' targetlist built for the UNION's toplevel query. Fix by making dummy targetlist a little less cheesy.
1 parent d72eb7c commit dd03129

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/backend/parser/analyze.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: analyze.c,v 1.163 2000/11/05 00:15:54 tgl Exp $
9+
* $Id: analyze.c,v 1.164 2000/11/05 01:42:07 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -1786,6 +1786,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
17861786
{
17871787
Query *qry = makeNode(Query);
17881788
SelectStmt *leftmostSelect;
1789+
int leftmostRTI;
17891790
Query *leftmostQuery;
17901791
SetOperationStmt *sostmt;
17911792
char *into;
@@ -1856,8 +1857,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
18561857
while (node && IsA(node, SetOperationStmt))
18571858
node = ((SetOperationStmt *) node)->larg;
18581859
Assert(node && IsA(node, RangeTblRef));
1859-
leftmostQuery = rt_fetch(((RangeTblRef *) node)->rtindex,
1860-
pstate->p_rtable)->subquery;
1860+
leftmostRTI = ((RangeTblRef *) node)->rtindex;
1861+
leftmostQuery = rt_fetch(leftmostRTI, pstate->p_rtable)->subquery;
18611862
Assert(leftmostQuery != NULL);
18621863
/*
18631864
* Generate dummy targetlist for outer query using column names of
@@ -1868,7 +1869,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
18681869
foreach(dtlist, sostmt->colTypes)
18691870
{
18701871
Oid colType = (Oid) lfirsti(dtlist);
1871-
char *colName = ((TargetEntry *) lfirst(lefttl))->resdom->resname;
1872+
Resdom *leftResdom = ((TargetEntry *) lfirst(lefttl))->resdom;
1873+
char *colName = leftResdom->resname;
18721874
Resdom *resdom;
18731875
Node *expr;
18741876

@@ -1877,8 +1879,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
18771879
-1,
18781880
pstrdup(colName),
18791881
false);
1880-
expr = (Node *) makeVar(1,
1881-
resdom->resno,
1882+
expr = (Node *) makeVar(leftmostRTI,
1883+
leftResdom->resno,
18821884
colType,
18831885
-1,
18841886
0);

0 commit comments

Comments
 (0)