|
3 | 3 | * back to source text
|
4 | 4 | *
|
5 | 5 | * 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 $ |
7 | 7 | *
|
8 | 8 | * This software is copyrighted by Jan Wieck - Hamburg.
|
9 | 9 | *
|
@@ -178,9 +178,9 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
|
178 | 178 | elog(ERROR, "get_ruledef: cannot connect to SPI manager");
|
179 | 179 |
|
180 | 180 | /*
|
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. |
184 | 184 | */
|
185 | 185 | if (plan_getrule == NULL)
|
186 | 186 | {
|
@@ -271,9 +271,9 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
|
271 | 271 | elog(ERROR, "get_viewdef: cannot connect to SPI manager");
|
272 | 272 |
|
273 | 273 | /*
|
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. |
277 | 277 | */
|
278 | 278 | if (plan_getview == NULL)
|
279 | 279 | {
|
@@ -769,8 +769,21 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
|
769 | 769 | appendStringInfo(buf, " WHERE ");
|
770 | 770 |
|
771 | 771 | 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 | + */ |
772 | 778 | query = (Query *) lfirst(actions);
|
773 | 779 |
|
| 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 | + |
774 | 787 | context.buf = buf;
|
775 | 788 | context.namespaces = makeList1(&dpns);
|
776 | 789 | context.varprefix = (length(query->rtable) != 1);
|
|
0 commit comments