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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: laurie(dot)burrow(at)powerconv(dot)alstom(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Possible problem with pg_get_viewdef on Postgres V8.0.0 rc4
Date: 2005-01-13 18:57:05
Message-ID: 12452.1105642625@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

laurie(dot)burrow(at)powerconv(dot)alstom(dot)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))
{

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Chris Jones 2005-01-13 23:57:11 BUG #1397: busy-loop hang on web server
Previous Message Magnus Hagander 2005-01-13 17:26:32 Re: rc4 and rc3, some deleted, but still needed text in the