make-expandRTE-cope-with-new-columns.patch
text/x-diff
Filename: make-expandRTE-cope-with-new-columns.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/parser/parse_relation.c | 0 | 0 |
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index ca32a37..dae6fb9 100644
*** a/src/backend/parser/parse_relation.c
--- b/src/backend/parser/parse_relation.c
*************** expandRTE(RangeTblEntry *rte, int rtinde
*** 2207,2217 ****
if (colnames)
{
! /* Assume there is one alias per target item */
! char *label = strVal(lfirst(aliasp_item));
*colnames = lappend(*colnames, makeString(pstrdup(label)));
- aliasp_item = lnext(aliasp_item);
}
if (colvars)
--- 2207,2235 ----
if (colnames)
{
! char *label;
!
! /*
! * We prefer to use the outer query's column aliases
! * as column names. However, in scenarios where
! * columns have been added to a view since the outer
! * query was originally parsed, there could be more
! * tlist items in the subquery than the outer query
! * knew about. In such cases, use the subquery's
! * column names if it has any, else fall back to
! * "?column?".
! */
! if (aliasp_item)
! {
! label = strVal(lfirst(aliasp_item));
! aliasp_item = lnext(aliasp_item);
! }
! else if (te->resname)
! label = te->resname;
! else
! label = "?column?";
*colnames = lappend(*colnames, makeString(pstrdup(label)));
}
if (colvars)