Skip to content

Commit f224847

Browse files
committed
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.
1 parent 03b4fc7 commit f224847

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/pl/plpgsql/src/pl_exec.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.228 2009/01/07 20:38:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.229 2009/01/14 09:53:51 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2782,13 +2782,19 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
27822782

27832783
/*
27842784
* Check for error, and set FOUND if appropriate (for historical reasons
2785-
* we set FOUND only for certain query types). Also Assert that we
2786-
* identified the statement type the same as SPI did.
2785+
* we set FOUND only for certain query types).
2786+
*
2787+
* Note: the command type indicated by return code might not match
2788+
* mod_stmt, if there is an INSTEAD OF rule rewriting an UPDATE into an
2789+
* INSERT, for example. In that case, the INSERT doesn't have canSetTag
2790+
* set, mod_stmt is false, and SPI_execute_plan sets SPI_processed to
2791+
* zero. We'll set FOUND to false here in that case. If the statement is
2792+
* rewritten into a utility statement, however, FOUND is left unchanged.
2793+
* Arguably that's a bug, but changing it now could break applications.
27872794
*/
27882795
switch (rc)
27892796
{
27902797
case SPI_OK_SELECT:
2791-
Assert(!stmt->mod_stmt);
27922798
exec_set_found(estate, (SPI_processed != 0));
27932799
break;
27942800

@@ -2798,13 +2804,11 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
27982804
case SPI_OK_INSERT_RETURNING:
27992805
case SPI_OK_UPDATE_RETURNING:
28002806
case SPI_OK_DELETE_RETURNING:
2801-
Assert(stmt->mod_stmt);
28022807
exec_set_found(estate, (SPI_processed != 0));
28032808
break;
28042809

28052810
case SPI_OK_SELINTO:
28062811
case SPI_OK_UTILITY:
2807-
Assert(!stmt->mod_stmt);
28082812
break;
28092813

28102814
default:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy