From fc8b81a291bf7e1acfcbd40ed344f323f1e93a94 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 6 Nov 2016 12:09:36 -0500 Subject: Need to do SPI_push/SPI_pop around expression evaluation in plpgsql. We must do this in case the expression evaluation results in calling another plpgsql function (or, really, anything using SPI). I missed the need for this when I converted exec_cast_value() from doing a simple InputFunctionCall() to doing ExecEvalExpr() in commit 1345cc67b. There is a SPI_push_conditional in InputFunctionCall(), so that there was no bug before that. Per bug #14414 from Marcos Castedo. Add a regression test based on his example, which was that a plpgsql function in a domain check constraint didn't work when assigning to a domain-type variable within plpgsql. Report: <20161106010947.1387.66380@wrigleys.postgresql.org> --- src/pl/plpgsql/src/pl_exec.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/pl') diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 470cf935df3..042b31fd77f 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -6300,6 +6300,8 @@ exec_cast_value(PLpgSQL_execstate *estate, ExprContext *econtext = estate->eval_econtext; MemoryContext oldcontext; + SPI_push(); + oldcontext = MemoryContextSwitchTo(get_eval_mcontext(estate)); econtext->caseValue_datum = value; @@ -6313,6 +6315,8 @@ exec_cast_value(PLpgSQL_execstate *estate, cast_entry->cast_in_use = false; MemoryContextSwitchTo(oldcontext); + + SPI_pop(); } } -- cgit v1.2.3