Re: [BUGS] BUG #14876: Segmentation fault with JSONB column used in store proc that gets used by view and later altered

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [BUGS] BUG #14876: Segmentation fault with JSONB column used in store proc that gets used by view and later altered
Дата
Msg-id 26672.1509050556@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [BUGS] BUG #14876: Segmentation fault with JSONB column used instore proc that gets used by view and later altered  (Michael Paquier <michael.paquier@gmail.com>)
Ответы Re: [BUGS] BUG #14876: Segmentation fault with JSONB column used in store proc that gets used by view and later altered  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: [BUGS] Segmentation fault with JSONB column from view passed intostored PL/PGSQL procedure that builds a new JSON return value
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [BUGS] BUG #14876: Segmentation fault with JSONB column used in store proc that gets used by view and later altered