diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-01-25 00:19:18 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-01-25 00:19:56 -0500 |
commit | 760f3c043ad4ee622b596d005ec31bb5e0322c4a (patch) | |
tree | c25bee99d164d7e5cd8d481f224d1acaf3f8b589 /doc/src | |
parent | 56a6317bf54625c7fdade6cd1ab38178bba42448 (diff) | |
download | postgresql-760f3c043ad4ee622b596d005ec31bb5e0322c4a.tar.gz postgresql-760f3c043ad4ee622b596d005ec31bb5e0322c4a.zip |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/func.sgml | 24 | ||||
-rw-r--r-- | doc/src/sgml/xfunc.sgml | 11 |
2 files changed, 29 insertions, 6 deletions
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 @@ </entry> <entry><type>text</type></entry> <entry> - Concatenate all arguments. NULL arguments are ignored. + Concatenate the text representations of all the arguments. + NULL arguments are ignored. </entry> <entry><literal>concat('abcde', 2, NULL, 22)</literal></entry> <entry><literal>abcde222</literal></entry> @@ -1411,8 +1412,8 @@ </entry> <entry><type>text</type></entry> <entry> - 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. </entry> <entry><literal>concat_ws(',', 'abcde', 2, NULL, 22)</literal></entry> <entry><literal>abcde,2,22</literal></entry> @@ -1522,8 +1523,9 @@ </entry> <entry><type>text</type></entry> <entry> - Format a string. This function is similar to the C function - <function>sprintf</>; but only the following conversion specifications + Format arguments according to a format string. + This function is similar to the C function + <function>sprintf</>, but only the following conversion specifications are recognized: <literal>%s</literal> interpolates the corresponding argument as a string; <literal>%I</literal> escapes its argument as an SQL identifier; <literal>%L</literal> escapes its argument as an @@ -2034,6 +2036,18 @@ </table> <para> + The <function>concat</function>, <function>concat_ws</function> and + <function>format</function> functions are variadic, so it is possible to + pass the values to be concatenated or formatted as an array marked with + the <literal>VARIADIC</literal> keyword (see <xref + linkend="xfunc-sql-variadic-functions">). The array's elements are + treated as if they were separate ordinary arguments to the function. + If the variadic array argument is NULL, <function>concat</function> + and <function>concat_ws</function> return NULL, but + <function>format</function> treats a NULL as a zero-element array. + </para> + + <para> See also the aggregate function <function>string_agg</function> in <xref linkend="functions-aggregate">. </para> 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, <literal>fcinfo->flinfo</>. The parameter <literal>argnum</> is zero based. <function>get_call_result_type</> can also be used as an alternative to <function>get_fn_expr_rettype</>. + There is also <function>get_fn_expr_variadic</>, which can be used to + find out whether the call contained an explicit <literal>VARIADIC</> + keyword. This is primarily useful for <literal>VARIADIC "any"</> + functions, as described below. </para> <para> @@ -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 <function>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 <literal>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 <function>get_fn_expr_variadic</> to + detect that the actual argument was marked with <literal>VARIADIC</>. </para> </sect2> |