From 760f3c043ad4ee622b596d005ec31bb5e0322c4a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 25 Jan 2013 00:19:18 -0500 Subject: Fix concat() and format() to handle VARIADIC-labeled arguments correctly. Previously, the VARIADIC labeling was effectively ignored, but now these functions act as though the array elements had all been given as separate arguments. Pavel Stehule --- doc/src/sgml/func.sgml | 24 +++++++++++++++++++----- doc/src/sgml/xfunc.sgml | 11 ++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 35c7f75eab2..e9dbcb9f8a0 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1394,7 +1394,8 @@ text - Concatenate all arguments. NULL arguments are ignored. + Concatenate the text representations of all the arguments. + NULL arguments are ignored. concat('abcde', 2, NULL, 22) abcde222 @@ -1411,8 +1412,8 @@ text - Concatenate all but first arguments with separators. The first - parameter is used as a separator. NULL arguments are ignored. + Concatenate all but the first argument with separators. The first + argument is used as the separator string. NULL arguments are ignored. concat_ws(',', 'abcde', 2, NULL, 22) abcde,2,22 @@ -1522,8 +1523,9 @@ text - Format a string. This function is similar to the C function - sprintf; but only the following conversion specifications + Format arguments according to a format string. + This function is similar to the C function + sprintf, but only the following conversion specifications are recognized: %s interpolates the corresponding argument as a string; %I escapes its argument as an SQL identifier; %L escapes its argument as an @@ -2033,6 +2035,18 @@ + + The concat, concat_ws and + format functions are variadic, so it is possible to + pass the values to be concatenated or formatted as an array marked with + the VARIADIC keyword (see ). The array's elements are + treated as if they were separate ordinary arguments to the function. + If the variadic array argument is NULL, concat + and concat_ws return NULL, but + format treats a NULL as a zero-element array. + + See also the aggregate function string_agg in . diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 85539feb0d2..4fb42842c6f 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -3153,6 +3153,10 @@ CREATE OR REPLACE FUNCTION retcomposite(IN integer, IN integer, fcinfo->flinfo. The parameter argnum is zero based. get_call_result_type can also be used as an alternative to get_fn_expr_rettype. + There is also get_fn_expr_variadic, which can be used to + find out whether the call contained an explicit VARIADIC + keyword. This is primarily useful for VARIADIC "any" + functions, as described below. @@ -3229,7 +3233,12 @@ CREATE FUNCTION make_array(anyelement) RETURNS anyarray as happens with normal variadic functions; they will just be passed to the function separately. The PG_NARGS() macro and the methods described above must be used to determine the number of actual - arguments and their types when using this feature. + arguments and their types when using this feature. Also, users of such + a function might wish to use the VARIADIC keyword in their + function call, with the expectation that the function would treat the + array elements as separate arguments. The function itself must implement + that behavior if wanted, after using get_fn_expr_variadic to + detect that the actual argument was marked with VARIADIC. -- cgit v1.2.3