Skip to content

Commit 29fa051

Browse files
committed
When executing a list of queries derived from rule expansion,
_SPI_execute_plan's return code should reflect the type of the query that is marked canSetTag, not necessarily the last one in the list. This is arguably a bug fix, but I'm hesitant to back-patch it because it's the sort of subtle change that might break someone's code, and it's best not to do that kind of thing in point releases.
1 parent c859294 commit 29fa051

File tree

1 file changed

+12
-7
lines changed
  • src/backend/executor

1 file changed

+12
-7
lines changed

src/backend/executor/spi.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.155 2006/08/12 20:05:55 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.156 2006/08/14 13:40:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1306,7 +1306,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
13061306
Snapshot snapshot, Snapshot crosscheck_snapshot,
13071307
bool read_only, long tcount)
13081308
{
1309-
volatile int res = 0;
1309+
volatile int my_res = 0;
13101310
volatile uint32 my_processed = 0;
13111311
volatile Oid my_lastoid = InvalidOid;
13121312
SPITupleTable *volatile my_tuptable = NULL;
@@ -1364,6 +1364,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
13641364
Plan *planTree;
13651365
QueryDesc *qdesc;
13661366
DestReceiver *dest;
1367+
int res;
13671368

13681369
planTree = lfirst(plan_list_item);
13691370
plan_list_item = lnext(plan_list_item);
@@ -1380,20 +1381,20 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
13801381

13811382
if (stmt->filename == NULL)
13821383
{
1383-
res = SPI_ERROR_COPY;
1384+
my_res = SPI_ERROR_COPY;
13841385
goto fail;
13851386
}
13861387
}
13871388
else if (IsA(queryTree->utilityStmt, DeclareCursorStmt) ||
13881389
IsA(queryTree->utilityStmt, ClosePortalStmt) ||
13891390
IsA(queryTree->utilityStmt, FetchStmt))
13901391
{
1391-
res = SPI_ERROR_CURSOR;
1392+
my_res = SPI_ERROR_CURSOR;
13921393
goto fail;
13931394
}
13941395
else if (IsA(queryTree->utilityStmt, TransactionStmt))
13951396
{
1396-
res = SPI_ERROR_TRANSACTION;
1397+
my_res = SPI_ERROR_TRANSACTION;
13971398
goto fail;
13981399
}
13991400
}
@@ -1459,7 +1460,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
14591460
ActiveSnapshot = NULL;
14601461

14611462
/*
1462-
* The last canSetTag query sets the auxiliary values returned
1463+
* The last canSetTag query sets the status values returned
14631464
* to the caller. Be careful to free any tuptables not
14641465
* returned, to avoid intratransaction memory leak.
14651466
*/
@@ -1469,6 +1470,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
14691470
my_lastoid = _SPI_current->lastoid;
14701471
SPI_freetuptable(my_tuptable);
14711472
my_tuptable = _SPI_current->tuptable;
1473+
my_res = res;
14721474
}
14731475
else
14741476
{
@@ -1477,7 +1479,10 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
14771479
}
14781480
/* we know that the receiver doesn't need a destroy call */
14791481
if (res < 0)
1482+
{
1483+
my_res = res;
14801484
goto fail;
1485+
}
14811486
}
14821487
}
14831488

@@ -1503,7 +1508,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
15031508
SPI_lastoid = my_lastoid;
15041509
SPI_tuptable = my_tuptable;
15051510

1506-
return res;
1511+
return my_res;
15071512
}
15081513

15091514
static int

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