From dd03129b9f1e7b70161c04b227416b8bed4956cc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 5 Nov 2000 01:42:07 +0000 Subject: [PATCH] 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. --- src/backend/parser/analyze.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 45e81aec60..93edc9f878 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -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);