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_coerce.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'src/backend/parser/parse_coerce.c') diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index 8065b261beb..8d892fcffe1 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.120 2004/08/17 18:47:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.121 2004/08/19 20:57:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -662,29 +662,12 @@ coerce_record_to_complex(ParseState *pstate, Node *node, else if (node && IsA(node, Var) && ((Var *) node)->varattno == InvalidAttrNumber) { - RangeTblEntry *rte; - AttrNumber nfields; - AttrNumber nf; - - rte = GetRTEByRangeTablePosn(pstate, - ((Var *) node)->varno, - ((Var *) node)->varlevelsup); - nfields = list_length(rte->eref->colnames); - for (nf = 1; nf <= nfields; nf++) - { - Oid vartype; - int32 vartypmod; + int rtindex = ((Var *) node)->varno; + int sublevels_up = ((Var *) node)->varlevelsup; + List *rtable; - if (get_rte_attribute_is_dropped(rte, nf)) - continue; - get_rte_attribute_type(rte, nf, &vartype, &vartypmod); - args = lappend(args, - makeVar(((Var *) node)->varno, - nf, - vartype, - vartypmod, - ((Var *) node)->varlevelsup)); - } + rtable = GetLevelNRangeTable(pstate, sublevels_up); + expandRTE(rtable, rtindex, sublevels_up, false, NULL, &args); } else ereport(ERROR, -- cgit v1.2.3