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.
This commit is contained in:
Tom Lane 2000-11-05 01:42:07 +00:00
parent d72eb7cbbd
commit dd03129b9f
1 changed files with 8 additions and 6 deletions

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: analyze.c,v 1.163 2000/11/05 00:15:54 tgl Exp $
* $Id: analyze.c,v 1.164 2000/11/05 01:42:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1786,6 +1786,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
{
Query *qry = makeNode(Query);
SelectStmt *leftmostSelect;
int leftmostRTI;
Query *leftmostQuery;
SetOperationStmt *sostmt;
char *into;
@ -1856,8 +1857,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
while (node && IsA(node, SetOperationStmt))
node = ((SetOperationStmt *) node)->larg;
Assert(node && IsA(node, RangeTblRef));
leftmostQuery = rt_fetch(((RangeTblRef *) node)->rtindex,
pstate->p_rtable)->subquery;
leftmostRTI = ((RangeTblRef *) node)->rtindex;
leftmostQuery = rt_fetch(leftmostRTI, pstate->p_rtable)->subquery;
Assert(leftmostQuery != NULL);
/*
* Generate dummy targetlist for outer query using column names of
@ -1868,7 +1869,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
foreach(dtlist, sostmt->colTypes)
{
Oid colType = (Oid) lfirsti(dtlist);
char *colName = ((TargetEntry *) lfirst(lefttl))->resdom->resname;
Resdom *leftResdom = ((TargetEntry *) lfirst(lefttl))->resdom;
char *colName = leftResdom->resname;
Resdom *resdom;
Node *expr;
@ -1877,8 +1879,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
-1,
pstrdup(colName),
false);
expr = (Node *) makeVar(1,
resdom->resno,
expr = (Node *) makeVar(leftmostRTI,
leftResdom->resno,
colType,
-1,
0);