From bbd6eb5b958ef38f786089fd4a03d650d4b7220e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 19 Aug 2004 20:57:41 +0000 Subject: Repair some issues with column aliases and RowExpr construction in the presence of dropped columns. Document the already-presumed fact that eref aliases in relation RTEs are supposed to have entries for dropped columns; cause the user alias structs to have such entries too, so that there's always a one-to-one mapping to the underlying physical attnums. Adjust expandRTE() and related code to handle the case where a column that is part of a JOIN has been dropped. Generalize expandRTE()'s API so that it can be used in a couple of places that formerly rolled their own implementation of the same logic. Fix ruleutils.c to suppress display of aliases for columns that were dropped since the rule was made. --- src/backend/parser/parse_target.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/backend/parser/parse_target.c') diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 7dcbc7b7b7..1ca2b45793 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.122 2004/06/19 18:19:55 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.123 2004/08/19 20:57:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -699,6 +699,8 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref) char *relname; RangeTblEntry *rte; int sublevels_up; + int rtindex; + List *rtable; switch (numnames) { @@ -743,7 +745,10 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref) rte = addImplicitRTE(pstate, makeRangeVar(schemaname, relname)); - return expandRelAttrs(pstate, rte); + rtindex = RTERangeTablePosn(pstate, rte, &sublevels_up); + rtable = GetLevelNRangeTable(pstate, sublevels_up); + + return expandRelAttrs(pstate, rtable, rtindex, sublevels_up); } } @@ -765,29 +770,31 @@ ExpandAllTables(ParseState *pstate) foreach(ns, pstate->p_namespace) { Node *n = (Node *) lfirst(ns); + int rtindex; RangeTblEntry *rte; if (IsA(n, RangeTblRef)) - rte = rt_fetch(((RangeTblRef *) n)->rtindex, - pstate->p_rtable); + rtindex = ((RangeTblRef *) n)->rtindex; else if (IsA(n, JoinExpr)) - rte = rt_fetch(((JoinExpr *) n)->rtindex, - pstate->p_rtable); + rtindex = ((JoinExpr *) n)->rtindex; else { elog(ERROR, "unrecognized node type: %d", (int) nodeTag(n)); - rte = NULL; /* keep compiler quiet */ + rtindex = 0; /* keep compiler quiet */ } /* * Ignore added-on relations that were not listed in the FROM * clause. */ + rte = rt_fetch(rtindex, pstate->p_rtable); if (!rte->inFromCl) continue; found_table = true; - target = list_concat(target, expandRelAttrs(pstate, rte)); + target = list_concat(target, + expandRelAttrs(pstate, pstate->p_rtable, + rtindex, 0)); } /* Check for SELECT *; */ -- cgit v1.2.1