!3898 修复问题:replace(string,substring)函数2个参数一样时报错,预期返回null

Merge pull request !3898 from lukeman/master
This commit is contained in:
opengauss_bot
2023-08-14 02:14:05 +00:00
committed by Gitee
2 changed files with 27 additions and 8 deletions

View File

@ -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;
}
/*

View File

@ -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;