Re: Possible problem with pg_get_viewdef on Postgres V8.0.0 rc4

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Possible problem with pg_get_viewdef on Postgres V8.0.0 rc4
Дата
Msg-id 12452.1105642625@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Possible problem with pg_get_viewdef on Postgres V8.0.0 rc4  (laurie.burrow@powerconv.alstom.com)
Список pgsql-bugs
laurie.burrow@powerconv.alstom.com writes:
> Tom Lane wrote:
>> Could we see a full example?  The view definition is of little use when
>> you didn't provide the definitions of the tables it references.

>    Mea Culpa!

>    The view references prd, and rspper tables whose defintions are shown
>    below.

OK, I found the problem.  If you need a patch right away, it's attached.

            regards, tom lane


*** src/backend/utils/adt/ruleutils.c.orig    Sun Dec 12 19:33:06 2004
--- src/backend/utils/adt/ruleutils.c    Thu Jan 13 12:19:10 2005
***************
*** 182,188 ****
  static Node *get_rule_sortgroupclause(SortClause *srt, List *tlist,
                           bool force_colno,
                           deparse_context *context);
! static void get_names_for_var(Var *var, deparse_context *context,
                    char **schemaname, char **refname, char **attname);
  static RangeTblEntry *find_rte_by_refname(const char *refname,
                      deparse_context *context);
--- 182,188 ----
  static Node *get_rule_sortgroupclause(SortClause *srt, List *tlist,
                           bool force_colno,
                           deparse_context *context);
! static void get_names_for_var(Var *var, int levelsup, deparse_context *context,
                    char **schemaname, char **refname, char **attname);
  static RangeTblEntry *find_rte_by_refname(const char *refname,
                      deparse_context *context);
***************
*** 1998,2004 ****
                  char       *refname;
                  char       *attname;

!                 get_names_for_var(var, context,
                                    &schemaname, &refname, &attname);
                  tell_as = (attname == NULL ||
                             strcmp(attname, colname) != 0);
--- 1998,2004 ----
                  char       *refname;
                  char       *attname;

!                 get_names_for_var(var, 0, context,
                                    &schemaname, &refname, &attname);
                  tell_as = (attname == NULL ||
                             strcmp(attname, colname) != 0);
***************
*** 2392,2397 ****
--- 2392,2401 ----
  /*
   * Get the schemaname, refname and attname for a (possibly nonlocal) Var.
   *
+  * In some cases (currently only when recursing into an unnamed join)
+  * the Var's varlevelsup has to be interpreted with respect to a context
+  * above the current one; levelsup indicates the offset.
+  *
   * schemaname is usually returned as NULL.    It will be non-null only if
   * use of the unqualified refname would find the wrong RTE.
   *
***************
*** 2404,2420 ****
   * distinguish this case.)
   */
  static void
! get_names_for_var(Var *var, deparse_context *context,
                    char **schemaname, char **refname, char **attname)
  {
      deparse_namespace *dpns;
      RangeTblEntry *rte;

      /* Find appropriate nesting depth */
!     if (var->varlevelsup >= list_length(context->namespaces))
!         elog(ERROR, "bogus varlevelsup: %d", var->varlevelsup);
      dpns = (deparse_namespace *) list_nth(context->namespaces,
!                                           var->varlevelsup);

      /* Find the relevant RTE */
      if (var->varno >= 1 && var->varno <= list_length(dpns->rtable))
--- 2408,2427 ----
   * distinguish this case.)
   */
  static void
! get_names_for_var(Var *var, int levelsup, deparse_context *context,
                    char **schemaname, char **refname, char **attname)
  {
+     int            netlevelsup;
      deparse_namespace *dpns;
      RangeTblEntry *rte;

      /* Find appropriate nesting depth */
!     netlevelsup = var->varlevelsup + levelsup;
!     if (netlevelsup >= list_length(context->namespaces))
!         elog(ERROR, "bogus varlevelsup: %d offset %d",
!              var->varlevelsup, levelsup);
      dpns = (deparse_namespace *) list_nth(context->namespaces,
!                                           netlevelsup);

      /* Find the relevant RTE */
      if (var->varno >= 1 && var->varno <= list_length(dpns->rtable))
***************
*** 2467,2473 ****
                                              var->varattno-1);
                  if (IsA(aliasvar, Var))
                  {
!                     get_names_for_var(aliasvar, context,
                                        schemaname, refname, attname);
                      return;
                  }
--- 2474,2480 ----
                                              var->varattno-1);
                  if (IsA(aliasvar, Var))
                  {
!                     get_names_for_var(aliasvar, netlevelsup, context,
                                        schemaname, refname, attname);
                      return;
                  }
***************
*** 2867,2873 ****
                  char       *refname;
                  char       *attname;

!                 get_names_for_var(var, context,
                                    &schemaname, &refname, &attname);
                  if (refname && (context->varprefix || attname == NULL))
                  {
--- 2874,2880 ----
                  char       *refname;
                  char       *attname;

!                 get_names_for_var(var, 0, context,
                                    &schemaname, &refname, &attname);
                  if (refname && (context->varprefix || attname == NULL))
                  {

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

Предыдущее
От: laurie.burrow@powerconv.alstom.com
Дата:
Сообщение: Re: Possible problem with pg_get_viewdef on Postgres V8.0.0 rc4
Следующее
От: Tony Caduto
Дата:
Сообщение: Re: BUG #1375: Problem with Dollar qouting functions