aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_clause.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-06 02:12:56 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-06 02:12:56 +0000
commit0ff384f0bcd1a828dc994f02cbbd8bfc3405e94d (patch)
treee7036f8f1f6ac1c19b27aff95c98fa6669f8a975 /src/backend/parser/parse_clause.c
parentaf88c9bbecf56afa2f2d7abe1dad927ca0287261 (diff)
downloadpostgresql-0ff384f0bcd1a828dc994f02cbbd8bfc3405e94d.tar.gz
postgresql-0ff384f0bcd1a828dc994f02cbbd8bfc3405e94d.zip
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.
Diffstat (limited to 'src/backend/parser/parse_clause.c')
-rw-r--r--src/backend/parser/parse_clause.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index dbf17759617..0e5fbfd28ac 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -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 */