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

Commita5b7640

Browse files
committed
Fix concat_ws() to not insert a separator after leading NULL argument(s).
Per bug #6181 from Itagaki Takahiro. Also do some marginal code cleanupand improve error handling.
1 parentbe1e805 commita5b7640

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

‎src/backend/utils/adt/varlena.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,11 +3622,19 @@ string_agg_finalfn(PG_FUNCTION_ARGS)
36223622
PG_RETURN_NULL();
36233623
}
36243624

3625+
/*
3626+
* Implementation of both concat() and concat_ws().
3627+
*
3628+
* sepstr/seplen describe the separator. argidx is the first argument
3629+
* to concatenate (counting from zero).
3630+
*/
36253631
statictext*
3626-
concat_internal(constchar*sepstr,intseplen,intargidx,FunctionCallInfofcinfo)
3632+
concat_internal(constchar*sepstr,intseplen,intargidx,
3633+
FunctionCallInfofcinfo)
36273634
{
3628-
StringInfoDatastr;
36293635
text*result;
3636+
StringInfoDatastr;
3637+
boolfirst_arg= true;
36303638
inti;
36313639

36323640
initStringInfo(&str);
@@ -3635,17 +3643,21 @@ concat_internal(const char *sepstr, int seplen, int argidx, FunctionCallInfo fci
36353643
{
36363644
if (!PG_ARGISNULL(i))
36373645
{
3646+
Datumvalue=PG_GETARG_DATUM(i);
36383647
Oidvaltype;
3639-
Datumvalue;
36403648
OidtypOutput;
36413649
booltypIsVarlena;
36423650

3643-
if (i>argidx)
3651+
/* add separator if appropriate */
3652+
if (first_arg)
3653+
first_arg= false;
3654+
else
36443655
appendBinaryStringInfo(&str,sepstr,seplen);
36453656

3646-
/* append n-th value */
3647-
value=PG_GETARG_DATUM(i);
3657+
/* call the appropriate type output function, append the result */
36483658
valtype=get_fn_expr_argtype(fcinfo->flinfo,i);
3659+
if (!OidIsValid(valtype))
3660+
elog(ERROR,"could not determine data type of concat() input");
36493661
getTypeOutputInfo(valtype,&typOutput,&typIsVarlena);
36503662
appendStringInfoString(&str,
36513663
OidOutputFunctionCall(typOutput,value));
@@ -3664,12 +3676,12 @@ concat_internal(const char *sepstr, int seplen, int argidx, FunctionCallInfo fci
36643676
Datum
36653677
text_concat(PG_FUNCTION_ARGS)
36663678
{
3667-
PG_RETURN_TEXT_P(concat_internal(NULL,0,0,fcinfo));
3679+
PG_RETURN_TEXT_P(concat_internal("",0,0,fcinfo));
36683680
}
36693681

36703682
/*
3671-
* Concatenate all but first argumentvalues with separators. The first
3672-
* parameter is used asa separator. NULL arguments are ignored.
3683+
* Concatenate all but first argumentvalue with separators. The first
3684+
* parameter is used asthe separator. NULL arguments are ignored.
36733685
*/
36743686
Datum
36753687
text_concat_ws(PG_FUNCTION_ARGS)
@@ -3682,8 +3694,8 @@ text_concat_ws(PG_FUNCTION_ARGS)
36823694

36833695
sep=PG_GETARG_TEXT_PP(0);
36843696

3685-
PG_RETURN_TEXT_P(concat_internal(
3686-
VARDATA_ANY(sep),VARSIZE_ANY_EXHDR(sep),1,fcinfo));
3697+
PG_RETURN_TEXT_P(concat_internal(VARDATA_ANY(sep),VARSIZE_ANY_EXHDR(sep),
3698+
1,fcinfo));
36873699
}
36883700

36893701
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp