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/0500:15:54 tgl Exp $
9+ *$Id: analyze.c,v 1.164 2000/11/0501:42:07 tgl Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -1786,6 +1786,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
17861786{
17871787Query * qry = makeNode (Query );
17881788SelectStmt * leftmostSelect ;
1789+ int leftmostRTI ;
17891790Query * leftmostQuery ;
17901791SetOperationStmt * sostmt ;
17911792char * into ;
@@ -1856,8 +1857,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
18561857while (node && IsA (node ,SetOperationStmt ))
18571858node = ((SetOperationStmt * )node )-> larg ;
18581859Assert (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 ;
18611862Assert (leftmostQuery != NULL );
18621863/*
18631864 * Generate dummy targetlist for outer query using column names of
@@ -1868,7 +1869,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
18681869foreach (dtlist ,sostmt -> colTypes )
18691870{
18701871Oid colType = (Oid )lfirsti (dtlist );
1871- char * colName = ((TargetEntry * )lfirst (lefttl ))-> resdom -> resname ;
1872+ Resdom * leftResdom = ((TargetEntry * )lfirst (lefttl ))-> resdom ;
1873+ char * colName = leftResdom -> resname ;
18721874Resdom * resdom ;
18731875Node * expr ;
18741876
@@ -1877,8 +1879,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
18771879-1 ,
18781880pstrdup (colName ),
18791881false);
1880- expr = (Node * )makeVar (1 ,
1881- resdom -> resno ,
1882+ expr = (Node * )makeVar (leftmostRTI ,
1883+ leftResdom -> resno ,
18821884colType ,
18831885-1 ,
188418860 );