1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Fix the implicit-RTE code to be able to handle implicit RTEs for CTEs, as

well as regular tables.  Per discussion, this seems necessary to meet the
principle of least astonishment.

In passing, simplify the error messages in warnAutoRange().  Now that we
have parser error position info for these errors, it doesn't seem very
useful to word the error message differently depending on whether we are
inside a sub-select or not.
This commit is contained in:
Tom Lane
2008-10-06 02:12:56 +00:00
parent af88c9bbec
commit 0ff384f0bc
3 changed files with 87 additions and 49 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.180 2008/10/04 21:56:54 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.181 2008/10/06 02:12:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -631,34 +631,15 @@ transformFromClauseItem(ParseState *pstate, Node *n,
RangeTblEntry *rte = NULL;
int rtindex;
/*
* If it is an unqualified name, it might be a reference to some
* CTE visible in this or a parent query.
*/
/* if it is an unqualified name, it might be a CTE reference */
if (!rv->schemaname)
{
ParseState *ps;
CommonTableExpr *cte;
Index levelsup;
for (ps = pstate, levelsup = 0;
ps != NULL;
ps = ps->parentParseState, levelsup++)
{
ListCell *lc;
foreach(lc, ps->p_ctenamespace)
{
CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc);
if (strcmp(rv->relname, cte->ctename) == 0)
{
rte = transformCTEReference(pstate, rv, cte, levelsup);
break;
}
}
if (rte)
break;
}
cte = scanNameSpaceForCTE(pstate, rv->relname, &levelsup);
if (cte)
rte = transformCTEReference(pstate, rv, cte, levelsup);
}
/* if not found as a CTE, must be a table reference */