aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-01-14 09:53:54 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-01-14 09:53:54 +0000
commit09156de6404b18cb5b68c58b3e52422d10f73cb0 (patch)
treec6afe33a976b0ca9e7535dc8442884044e8ccef3
parent4d4b0f35210bc7c83b73fc4e001e8873982de722 (diff)
downloadpostgresql-09156de6404b18cb5b68c58b3e52422d10f73cb0.tar.gz
postgresql-09156de6404b18cb5b68c58b3e52422d10f73cb0.zip
Remove broken Assertions that failed if a statement executed in PL/pgSQL is
rewritten into another kind of statement, for example if an INSERT is rewritten into an UPDATE. Back-patch to 8.3 and 8.2. For HEAD, Tom suggested inventing a new SPI_OK_REWRITTEN return code, but that's not a backportable solution. I'll do that as a separate patch, this patch will do as a stopgap measure for HEAD too in the meanwhile.
-rw-r--r--src/pl/plpgsql/src/pl_exec.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index c9a1fbeff4b..414c552ac3f 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.202.2.2 2009/01/07 20:39:05 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.202.2.3 2009/01/14 09:53:54 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2546,13 +2546,19 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
/*
* Check for error, and set FOUND if appropriate (for historical reasons
- * we set FOUND only for certain query types). Also Assert that we
- * identified the statement type the same as SPI did.
+ * we set FOUND only for certain query types).
+ *
+ * Note: the command type indicated by return code might not match
+ * mod_stmt, if there is an INSTEAD OF rule rewriting an UPDATE into an
+ * INSERT, for example. In that case, the INSERT doesn't have canSetTag
+ * set, mod_stmt is false, and SPI_execute_plan sets SPI_processed to
+ * zero. We'll set FOUND to false here in that case. If the statement is
+ * rewritten into a utility statement, however, FOUND is left unchanged.
+ * Arguably that's a bug, but changing it now could break applications.
*/
switch (rc)
{
case SPI_OK_SELECT:
- Assert(!stmt->mod_stmt);
exec_set_found(estate, (SPI_processed != 0));
break;
@@ -2562,13 +2568,11 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
case SPI_OK_INSERT_RETURNING:
case SPI_OK_UPDATE_RETURNING:
case SPI_OK_DELETE_RETURNING:
- Assert(stmt->mod_stmt);
exec_set_found(estate, (SPI_processed != 0));
break;
case SPI_OK_SELINTO:
case SPI_OK_UTILITY:
- Assert(!stmt->mod_stmt);
break;
default: