-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix segfault when using certain DO block in function (#7554)
When using a CASE WHEN expression in the body of the function that is used in the DO block, a segmentation fault occured. This fixes that. Fixes #7381 --------- Co-authored-by: Konstantin Morozov <vzbdryn@yahoo.com> (cherry picked from commit 12f5643)
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
CREATE SCHEMA function_with_case; | ||
SET search_path TO function_with_case; | ||
-- create function | ||
CREATE OR REPLACE FUNCTION test_err(v1 text) | ||
RETURNS text | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
|
||
begin | ||
return v1 || ' - ok'; | ||
END; | ||
$function$; | ||
do $$ declare | ||
lNewValues text; | ||
val text; | ||
begin | ||
val = 'test'; | ||
lNewValues = test_err(v1 => case when val::text = 'test'::text then 'yes' else 'no' end); | ||
raise notice 'lNewValues= %', lNewValues; | ||
end;$$ ; | ||
NOTICE: lNewValues= yes - ok | ||
CONTEXT: PL/pgSQL function inline_code_block line XX at RAISE | ||
-- call function | ||
SELECT test_err('test'); | ||
test_err | ||
--------------------------------------------------------------------- | ||
test - ok | ||
(1 row) | ||
|
||
DROP SCHEMA function_with_case CASCADE; | ||
NOTICE: drop cascades to function test_err(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CREATE SCHEMA function_with_case; | ||
SET search_path TO function_with_case; | ||
|
||
-- create function | ||
CREATE OR REPLACE FUNCTION test_err(v1 text) | ||
RETURNS text | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
|
||
begin | ||
return v1 || ' - ok'; | ||
END; | ||
$function$; | ||
do $$ declare | ||
lNewValues text; | ||
val text; | ||
begin | ||
val = 'test'; | ||
lNewValues = test_err(v1 => case when val::text = 'test'::text then 'yes' else 'no' end); | ||
raise notice 'lNewValues= %', lNewValues; | ||
end;$$ ; | ||
|
||
-- call function | ||
SELECT test_err('test'); | ||
|
||
DROP SCHEMA function_with_case CASCADE; |