From 136cdd40637a8fa1e5fe4630303d273e5bfbca52 Mon Sep 17 00:00:00 2001 From: wuyuechuan Date: Tue, 11 Jul 2023 15:56:15 +0800 Subject: [PATCH] set return_number to correct number --- src/common/pl/plpgsql/src/pl_exec.cpp | 1 - src/gausskernel/runtime/executor/execQual.cpp | 7 +++++- .../regress/expected/plpgsql_override_out.out | 22 ++++++++++++++++++- src/test/regress/sql/plpgsql_override_out.sql | 14 ++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/common/pl/plpgsql/src/pl_exec.cpp b/src/common/pl/plpgsql/src/pl_exec.cpp index 09c891a78..deccaae49 100644 --- a/src/common/pl/plpgsql/src/pl_exec.cpp +++ b/src/common/pl/plpgsql/src/pl_exec.cpp @@ -4365,7 +4365,6 @@ static int exec_stmt_b_getdiag(PLpgSQL_execstate* estate, PLpgSQL_stmt_getdiag* StringInfoData buf; int condCount = 0; int condition_number = 0; - int currIdx = 0; int ret = 0; /* diff --git a/src/gausskernel/runtime/executor/execQual.cpp b/src/gausskernel/runtime/executor/execQual.cpp index 1eebc4074..69a49a6d8 100644 --- a/src/gausskernel/runtime/executor/execQual.cpp +++ b/src/gausskernel/runtime/executor/execQual.cpp @@ -2982,7 +2982,12 @@ extern bool func_has_refcursor_args(Oid Funcid, FunctionCallInfoData* fcinfo) } else if (return_refcursor) { fcinfo->refcursor_data.return_number = out_count; } - + /* func_has_out_param means whether a func with out param and with GUC proc_outparam_override. */ + bool func_has_out_param = is_function_with_plpgsql_language_and_outparam((fcinfo->flinfo)->fn_oid); + if (func_has_out_param && (return_refcursor || procStruct->prorettype == REFCURSOROID)) { + fcinfo->refcursor_data.return_number = out_count + 1; + } + ReleaseSysCache(proctup); return use_cursor; } diff --git a/src/test/regress/expected/plpgsql_override_out.out b/src/test/regress/expected/plpgsql_override_out.out index 0a71ab4be..52de16a6f 100644 --- a/src/test/regress/expected/plpgsql_override_out.out +++ b/src/test/regress/expected/plpgsql_override_out.out @@ -1004,6 +1004,24 @@ end; / ERROR: Named argument "b" can not be a const CONTEXT: compilation of PL/pgSQL function "inline_code_block" near line 4 +create table test_table2 (coll int,col2 text); +insert into test_table2 values (1, 'test'); +create or replace function test_function2(out rl refcursor, out r2 refcursor) +returns refcursor as +$$ +begin +open rl for select coll from test_table2; +open r2 for select col2 from test_table2; +return r2; +end; +$$ +LANGUAGE 'plpgsql'; +call test_function2('',''); + test_function2 | rl | r2 +--------------------+--------------------+-------------------- + | | +(1 row) + set plsql_compile_check_options=''; drop package body if exists pck1; drop package body pck1; @@ -1017,7 +1035,7 @@ NOTICE: drop cascades to 2 other objects --?.* --?.* drop schema if exists plpgsql_override_out cascade; -NOTICE: drop cascades to 15 other objects +NOTICE: drop cascades to 17 other objects DETAIL: drop cascades to function iob_proc(integer,integer) drop cascades to function bio_proc(integer,integer) drop cascades to function obi_proc(integer,integer) @@ -1033,3 +1051,5 @@ drop cascades to function plpgsql_override_out.p11() drop cascades to function p11() drop cascades to function plpgsql_override_out.p11() drop cascades to function p11(integer) +drop cascades to table test_table2 +drop cascades to function test_function2() diff --git a/src/test/regress/sql/plpgsql_override_out.sql b/src/test/regress/sql/plpgsql_override_out.sql index 096ce1f16..04d87cbc9 100644 --- a/src/test/regress/sql/plpgsql_override_out.sql +++ b/src/test/regress/sql/plpgsql_override_out.sql @@ -696,6 +696,20 @@ perform pck1.p1(a=>(1,'bb','11'),c=>var1,b=>'aa');--报错 end; / +create table test_table2 (coll int,col2 text); +insert into test_table2 values (1, 'test'); +create or replace function test_function2(out rl refcursor, out r2 refcursor) +returns refcursor as +$$ +begin +open rl for select coll from test_table2; +open r2 for select col2 from test_table2; +return r2; +end; +$$ +LANGUAGE 'plpgsql'; +call test_function2('',''); + set plsql_compile_check_options=''; drop package body if exists pck1; drop package body pck1;