summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorAndrew Dunstan2017-10-25 11:13:11 +0000
committerAndrew Dunstan2017-10-25 11:20:48 +0000
commit7f89fc418223d7bfe5cafd5b781a84332954f82a (patch)
tree1bbbcd07905ea69df95d4ca015dfa5b66b44c7d2 /src/include
parentba67fac85487e957ea98be8d06508bd2ebbd52f2 (diff)
Add a utility function to extract variadic function arguments
This is epecially useful in the case or "VARIADIC ANY" functions. The caller can get the artguments and types regardless of whether or not and explicit VARIADIC array argument has been used. The function also provides an option to convert arguments on type "unknown" to to "text". Michael Paquier and me, reviewed by Tom Lane. Backpatch to 9.4 in order to support the following json bug fix.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/funcapi.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/include/funcapi.h b/src/include/funcapi.h
index 6590a088c92..37f9b3b56c7 100644
--- a/src/include/funcapi.h
+++ b/src/include/funcapi.h
@@ -2,6 +2,7 @@
*
* funcapi.h
* Definitions for functions which return composite type and/or sets
+ * or work on VARIADIC inputs.
*
* This file must be included by all Postgres modules that either define
* or call FUNCAPI-callable functions or macros.
@@ -314,4 +315,26 @@ extern void end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext *funcctx);
PG_RETURN_NULL(); \
} while (0)
+/*----------
+ * Support to ease writing of functions dealing with VARIADIC inputs
+ *----------
+ *
+ * This function extracts a set of argument values, types and NULL markers
+ * for a given input function. This returns a set of data:
+ * - **values includes the set of Datum values extracted.
+ * - **types the data type OID for each element.
+ * - **nulls tracks if an element is NULL.
+ *
+ * variadic_start indicates the argument number where the VARIADIC argument
+ * starts.
+ * convert_unknown set to true will enforce the conversion of arguments
+ * with unknown data type to text.
+ *
+ * The return result is the number of elements stored, or -1 in the case of
+ * "VARIADIC NULL".
+ */
+extern int extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start,
+ bool convert_unknown, Datum **values,
+ Oid **types, bool **nulls);
+
#endif /* FUNCAPI_H */