summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-05-23 17:09:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-05-23 17:09:18 +0000
commitf966dccb2f702607d18c6ea991e3772f0d0415bd (patch)
tree126f9319b6e6b7d057360c27704eac62d0a8388a /src
parentf39fc4769ebac262fafa63ef029db971d3f11dc4 (diff)
downloadpostgresql-f966dccb2f702607d18c6ea991e3772f0d0415bd.tar.gz
Klugy fix for bug #2447: we can't expand a whole-row reference to NEW
in a rule WHERE expression while inserting it into the original query, because the 8.0 ResolveNew API is wrongly designed. This is fixed in 8.1 but I'm disinclined to risk back-porting the changes. Instead, just stop the coredump and instead issue the same 'cannot handle whole-row reference' message that 7.4 and before generated in this situation.
Diffstat (limited to 'src')
-rw-r--r--src/backend/rewrite/rewriteHandler.c4
-rw-r--r--src/backend/rewrite/rewriteManip.c20
2 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 4bc66db0bc..a9843f0d82 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.147 2004/12/31 22:00:45 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.147.4.1 2006/05/23 17:09:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1046,7 +1046,7 @@ CopyAndAddInvertedQual(Query *parsetree,
new_qual = ResolveNew(new_qual,
PRS2_NEW_VARNO,
0,
- parsetree->rtable,
+ NIL, /* fix bug #2447 */
parsetree->targetList,
event,
rt_index);
diff --git a/src/backend/rewrite/rewriteManip.c b/src/backend/rewrite/rewriteManip.c
index 75e1fb562e..9542848ac0 100644
--- a/src/backend/rewrite/rewriteManip.c
+++ b/src/backend/rewrite/rewriteManip.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.89.4.1 2006/01/06 20:11:24 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.89.4.2 2006/05/23 17:09:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -943,6 +943,24 @@ ResolveNew_mutator(Node *node, ResolveNew_context *context)
List *fields;
/*
+ * Klugy fix for bug #2447: we can't expand a whole-row
+ * reference to "NEW" in a rule WHERE expression while
+ * inserting it into the original query, because its varno
+ * will be PRS2_NEW_VARNO which is not the rtindex of the RTE
+ * we should use. The 8.0 ResolveNew API is wrongly designed.
+ * We aren't going to try to back-port the 8.1 API, just avoid
+ * crashing. (This never worked before 8.0, either.)
+ * CopyAndAddInvertedQual passes NIL for target_rtable, so
+ * testing for NIL would be sufficient, but let's put in a
+ * full check on the rtindex for safety.
+ */
+ if (this_varno < 1 ||
+ this_varno > list_length(context->target_rtable))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot handle whole-row reference")));
+
+ /*
* If generating an expansion for a var of a named rowtype
* (ie, this is a plain relation RTE), then we must
* include dummy items for dropped columns. If the var is