Re: BUG #1002: Update using rule on view with inheritance alters 0 rows, 1 row expected.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: christopher-piker(at)uiowa(dot)edu
Cc: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #1002: Update using rule on view with inheritance alters 0 rows, 1 row expected.
Date: 2003-12-09 01:58:11
Message-ID: 25758.1070935091@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
> The following query updates 0 rows, when 1 row is
> expected to be updated:

Nice catch. The attached patch seems to fix it.

regards, tom lane

*** src/backend/optimizer/util/clauses.c.orig Sat Nov 29 14:51:51 2003
--- src/backend/optimizer/util/clauses.c Mon Dec 8 20:41:07 2003
***************
*** 2960,2995 ****
RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
RangeTblEntry *newrte;

switch (rte->rtekind)
{
case RTE_RELATION:
case RTE_SPECIAL:
! /* nothing to do, don't bother to make a copy */
break;
case RTE_SUBQUERY:
if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
{
- FLATCOPY(newrte, rte, RangeTblEntry);
CHECKFLATCOPY(newrte->subquery, rte->subquery, Query);
MUTATE(newrte->subquery, newrte->subquery, Query *);
- rte = newrte;
}
break;
case RTE_JOIN:
if (!(flags & QTW_IGNORE_JOINALIASES))
{
- FLATCOPY(newrte, rte, RangeTblEntry);
MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
- rte = newrte;
}
break;
case RTE_FUNCTION:
- FLATCOPY(newrte, rte, RangeTblEntry);
MUTATE(newrte->funcexpr, rte->funcexpr, Node *);
- rte = newrte;
break;
}
! FastAppend(&newrt, rte);
}
query->rtable = FastListValue(&newrt);
return query;
--- 2960,2990 ----
RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
RangeTblEntry *newrte;

+ FLATCOPY(newrte, rte, RangeTblEntry);
switch (rte->rtekind)
{
case RTE_RELATION:
case RTE_SPECIAL:
! /* we don't bother to copy eref, aliases, etc; OK? */
break;
case RTE_SUBQUERY:
if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
{
CHECKFLATCOPY(newrte->subquery, rte->subquery, Query);
MUTATE(newrte->subquery, newrte->subquery, Query *);
}
break;
case RTE_JOIN:
if (!(flags & QTW_IGNORE_JOINALIASES))
{
MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
}
break;
case RTE_FUNCTION:
MUTATE(newrte->funcexpr, rte->funcexpr, Node *);
break;
}
! FastAppend(&newrt, newrte);
}
query->rtable = FastListValue(&newrt);
return query;

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2003-12-09 03:36:41 Re: Bug in pg_restore or in postmaster itself?
Previous Message PostgreSQL Bugs List 2003-12-08 23:35:56 BUG #1002: Update using rule on view with inheritance alters 0 rows, 1 row expected.