Michael Paquier <michael.paquier@gmail.com> writes:
> I haven't looked at this thing in details. But this data may not be
> present forever, say github.com is down or is removed from existence.
> So if you can, please always attach any self-contained test case in a
> way that it is saved in the archives of postgresql.org. In this case,
> that would have been to email directly pgsql-bugs instead of using the
> website form.
Thanks for posting the reproducer. The attached seems to fix it, but
now that I've seen this, I wonder if there are other similar cases.
regards, tom lane
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)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs