Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc8b81a

Browse files
committed
Need to do SPI_push/SPI_pop around expression evaluation in plpgsql.
We must do this in case the expression evaluation results in callinganother plpgsql function (or, really, anything using SPI). I missedthe need for this when I converted exec_cast_value() from doing asimple InputFunctionCall() to doing ExecEvalExpr() in commit1345cc6.There is a SPI_push_conditional in InputFunctionCall(), so that therewas no bug before that.Per bug #14414 from Marcos Castedo. Add a regression test based on hisexample, which was that a plpgsql function in a domain check constraintdidn't work when assigning to a domain-type variable within plpgsql.Report: <20161106010947.1387.66380@wrigleys.postgresql.org>
1 parent5485c99 commitfc8b81a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6300,6 +6300,8 @@ exec_cast_value(PLpgSQL_execstate *estate,
63006300
ExprContext*econtext=estate->eval_econtext;
63016301
MemoryContextoldcontext;
63026302

6303+
SPI_push();
6304+
63036305
oldcontext=MemoryContextSwitchTo(get_eval_mcontext(estate));
63046306

63056307
econtext->caseValue_datum=value;
@@ -6313,6 +6315,8 @@ exec_cast_value(PLpgSQL_execstate *estate,
63136315
cast_entry->cast_in_use= false;
63146316

63156317
MemoryContextSwitchTo(oldcontext);
6318+
6319+
SPI_pop();
63166320
}
63176321
}
63186322

‎src/test/regress/expected/plpgsql.out

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5643,3 +5643,22 @@ end;
56435643
$$;
56445644
ERROR: unhandled assertion
56455645
CONTEXT: PL/pgSQL function inline_code_block line 3 at ASSERT
5646+
-- Test use of plpgsql in a domain check constraint (cf. bug #14414)
5647+
create function plpgsql_domain_check(val int) returns boolean as $$
5648+
begin return val > 0; end
5649+
$$ language plpgsql immutable;
5650+
create domain plpgsql_domain as integer check(plpgsql_domain_check(value));
5651+
do $$
5652+
declare v_test plpgsql_domain;
5653+
begin
5654+
v_test := 1;
5655+
end;
5656+
$$;
5657+
do $$
5658+
declare v_test plpgsql_domain := 1;
5659+
begin
5660+
v_test := 0; -- fail
5661+
end;
5662+
$$;
5663+
ERROR: value for domain plpgsql_domain violates check constraint "plpgsql_domain_check"
5664+
CONTEXT: PL/pgSQL function inline_code_block line 4 at assignment

‎src/test/regress/sql/plpgsql.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,3 +4428,25 @@ exception when others then
44284428
null;-- do nothing
44294429
end;
44304430
$$;
4431+
4432+
-- Test use of plpgsql in a domain check constraint (cf. bug #14414)
4433+
4434+
createfunctionplpgsql_domain_check(valint) returnsbooleanas $$
4435+
begin return val>0; end
4436+
$$ language plpgsql immutable;
4437+
4438+
createdomainplpgsql_domainasintegercheck(plpgsql_domain_check(value));
4439+
4440+
do $$
4441+
declare v_test plpgsql_domain;
4442+
begin
4443+
v_test :=1;
4444+
end;
4445+
$$;
4446+
4447+
do $$
4448+
declare v_test plpgsql_domain :=1;
4449+
begin
4450+
v_test :=0;-- fail
4451+
end;
4452+
$$;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp