Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e593349

Browse files
committed
Repair problem with listing rules that have a WHERE condition and
have an INSERT...SELECT as the first or only action. Per bug report from Sergio Pili.
1 parent 4bc8c8d commit e593349

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* back to source text
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.87 2001/11/19 19:51:20 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.88 2001/11/26 00:29:15 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -178,9 +178,9 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
178178
elog(ERROR, "get_ruledef: cannot connect to SPI manager");
179179

180180
/*
181-
* On the first call prepare the plan to lookup pg_proc. We read
182-
* pg_proc over the SPI manager instead of using the syscache to be
183-
* checked for read access on pg_proc.
181+
* On the first call prepare the plan to lookup pg_rewrite. We read
182+
* pg_rewrite over the SPI manager instead of using the syscache to be
183+
* checked for read access on pg_rewrite.
184184
*/
185185
if (plan_getrule == NULL)
186186
{
@@ -271,9 +271,9 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
271271
elog(ERROR, "get_viewdef: cannot connect to SPI manager");
272272

273273
/*
274-
* On the first call prepare the plan to lookup pg_proc. We read
275-
* pg_proc over the SPI manager instead of using the syscache to be
276-
* checked for read access on pg_proc.
274+
* On the first call prepare the plan to lookup pg_rewrite. We read
275+
* pg_rewrite over the SPI manager instead of using the syscache to be
276+
* checked for read access on pg_rewrite.
277277
*/
278278
if (plan_getview == NULL)
279279
{
@@ -769,8 +769,21 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
769769
appendStringInfo(buf, " WHERE ");
770770

771771
qual = stringToNode(ev_qual);
772+
773+
/*
774+
* We need to make a context for recognizing any Vars in the qual
775+
* (which can only be references to OLD and NEW). Use the rtable
776+
* of the first query in the action list for this purpose.
777+
*/
772778
query = (Query *) lfirst(actions);
773779

780+
/*
781+
* If the action is INSERT...SELECT, OLD/NEW have been pushed
782+
* down into the SELECT, and that's what we need to look at.
783+
* (Ugly kluge ... try to fix this when we redesign querytrees.)
784+
*/
785+
query = getInsertSelectQuery(query, NULL);
786+
774787
context.buf = buf;
775788
context.namespaces = makeList1(&dpns);
776789
context.varprefix = (length(query->rtable) != 1);

0 commit comments

Comments
 (0)