]> granicus.if.org Git - postgresql/commitdiff
UNION select in a CREATE RULE caused a weird error, because transformRuleStmt
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 Nov 2000 01:42:07 +0000 (01:42 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 Nov 2000 01:42:07 +0000 (01:42 +0000)
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

index 45e81aec60811d77b999c17da9d59dc9c961905e..93edc9f8781be215bacb144386b15af80f0c610e 100644 (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);