*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.57 2000/03/15 23:31:04 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.58 2000/03/23 07:38:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
setTargetTable(ParseState *pstate, char *relname)
{
RangeTblEntry *rte;
- int sublevels_up;
- if ((refnameRangeTablePosn(pstate, relname, &sublevels_up) == 0)
- || (sublevels_up != 0))
+ /* look for relname only at current nesting level... */
+ if (refnameRangeTablePosn(pstate, relname, NULL) == 0)
rte = addRangeTableEntry(pstate, relname,
makeAttr(relname, NULL),
FALSE, FALSE, FALSE);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.76 2000/03/19 00:19:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.77 2000/03/23 07:38:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
RangeTblEntry *rte;
int vnum;
+ int sublevels_up;
/*
* a relation
relname = rte->relname;
- vnum = refnameRangeTablePosn(pstate, rte->eref->relname, NULL);
+ vnum = refnameRangeTablePosn(pstate, rte->eref->relname,
+ &sublevels_up);
/*
* for func(relname), the param to the function is the tuple
*/
toid = typeTypeId(typenameType(relname));
/* replace it in the arg list */
- lfirst(i) = makeVar(vnum, 0, toid, -1, 0);
+ lfirst(i) = makeVar(vnum, 0, toid, -1, sublevels_up);
}
else if (!attisset)
{
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.38 2000/03/17 02:36:17 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.39 2000/03/23 07:38:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (strcmp(rte->eref->relname, refname) == 0)
rteList = lappend(rteList, rte);
}
- /* only allow correlated columns in WHERE clause */
- if (pstate->p_in_where_clause)
- pstate = pstate->parentParseState;
- else
- break;
+ pstate = pstate->parentParseState;
}
return rteList;
}
if (strcmp(rte->eref->relname, refname) == 0)
return rte;
}
- /* only allow correlated columns in WHERE clause */
- if (pstate->p_in_where_clause)
- pstate = pstate->parentParseState;
- else
- break;
+ pstate = pstate->parentParseState;
}
return NULL;
}
-/* given refname, return id of variable; position starts with 1 */
+/* given refname, return RT index (starting with 1) of the relation,
+ * and optionally get its nesting depth (0 = current). If sublevels_up
+ * is NULL, only consider rels at the current nesting level.
+ */
int
refnameRangeTablePosn(ParseState *pstate, char *refname, int *sublevels_up)
{
return index;
index++;
}
- /* only allow correlated columns in WHERE clause */
- if (pstate->p_in_where_clause)
- {
- pstate = pstate->parentParseState;
- if (sublevels_up)
- (*sublevels_up)++;
- }
+ pstate = pstate->parentParseState;
+ if (sublevels_up)
+ (*sublevels_up)++;
else
break;
}
{
List *et;
List *rtable;
- RangeTblEntry *rte_result;
+ RangeTblEntry *rte_result = NULL;
- rte_result = NULL;
while (pstate != NULL)
{
if (pstate->p_is_rule)
rte_result = rte;
}
- /* only allow correlated columns in WHERE clause */
- if (pstate->p_in_where_clause && rte_result == NULL)
- pstate = pstate->parentParseState;
- else
- break;
+ if (rte_result != NULL)
+ break; /* found */
+
+ pstate = pstate->parentParseState;
}
return rte_result;
}