From 10afc18f1f3ce31624d23a95f17b96aa9547b0b0 Mon Sep 17 00:00:00 2001 From: lukeman Date: Sat, 12 Aug 2023 15:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98=EF=BC=9Are?= =?UTF-8?q?place(string,substring)=E5=87=BD=E6=95=B02=E4=B8=AA=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=80=E6=A0=B7=E6=97=B6=E6=8A=A5=E9=94=99=EF=BC=8C?= =?UTF-8?q?=E9=A2=84=E6=9C=9F=E8=BF=94=E5=9B=9Enull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/varlena.cpp | 18 ++++++++++++------ .../regress/expected/not_accept_empty_str.out | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/common/backend/utils/adt/varlena.cpp b/src/common/backend/utils/adt/varlena.cpp index 40dcb0f66..129277cce 100644 --- a/src/common/backend/utils/adt/varlena.cpp +++ b/src/common/backend/utils/adt/varlena.cpp @@ -4323,14 +4323,20 @@ Datum replace_text_with_two_args(PG_FUNCTION_ARGS) { if (PG_ARGISNULL(0)) PG_RETURN_NULL(); - if (PG_ARGISNULL(1)) PG_RETURN_TEXT_P(PG_GETARG_TEXT_PP(0)); - - return DirectFunctionCall3(replace_text, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1), - CStringGetTextDatum("\0")); + FunctionCallInfoData locfcinfo; + Datum result; + InitFunctionCallInfoData(locfcinfo, NULL, 3, InvalidOid, NULL, NULL); + locfcinfo.arg[0] = PG_GETARG_DATUM(0); + locfcinfo.arg[1] = PG_GETARG_DATUM(1); + locfcinfo.arg[2] = CStringGetTextDatum("\0"); + locfcinfo.argnull[0] = false; + locfcinfo.argnull[1] = false; + locfcinfo.argnull[2] = false; + result = (*replace_text)(&locfcinfo); + fcinfo->isnull = locfcinfo.isnull; + return result; } /* diff --git a/src/test/regress/expected/not_accept_empty_str.out b/src/test/regress/expected/not_accept_empty_str.out index a2149a902..6cf91f8d4 100644 --- a/src/test/regress/expected/not_accept_empty_str.out +++ b/src/test/regress/expected/not_accept_empty_str.out @@ -885,7 +885,11 @@ SELECT replace('abc', 'ab') is null; (1 row) SELECT replace('abc', 'abc') is null; -ERROR: function returned NULL + ?column? +---------- + t +(1 row) + SELECT replace('abc', '') is null; ?column? ---------- @@ -1781,7 +1785,16 @@ SELECT a as p1, b as p2, c as p3, replace(a, b, c) is null from replace3; create table replace2 (a text, b text); insert into replace2 values('abc', 'ab'), ('abc', 'abc'), ('abc', ''), ('abc', null), ('', 'ab'), (null, 'ab'); SELECT a as p1, b as p2, replace(a, b) is null from replace2; -ERROR: function returned NULL + p1 | p2 | ?column? +-----+-----+---------- + abc | ab | f + abc | abc | t + abc | | f + abc | | f + | ab | t + | ab | t +(6 rows) + create table split_part3 (a text, b text, c int); insert into split_part3 values('1~2~3', '~', 3), ('1~2~3~', '~', 4), ('1~2~3', '', 1), ('1~2~3', null, 1), ('', '~', 1), (null, '~', 1); SELECT a as p1, b as p2, c as p3, split_part(a, b, c) is null from split_part3;