In PostgreSQL, VARIADIC can appear in two places: (1) in CREATE FUNCTION to declare the last parameter as a variable-length array, and (2) in a function call to expand an existing array into individual arguments. When declared, any number of positional arguments supplied after the fixed parameters are automatically packed into a single array that the function receives. When used in a call, an array expression is unpacked so each element is passed as a separate argument. Only the final parameter of a function may be marked VARIADIC, and it must be a one-dimensional array type (e.g., text[]). VARIADIC parameters cannot be declared OUT or INOUT. Calls may omit the VARIADIC keyword and pass a plain list, or include it and supply an explicit array. Mixing named notation and VARIADIC is unsupported. This feature simplifies writing utility functions such as custom aggregators, comparison helpers (greatest, least), or dynamic SQL builders.
func_name
(identifier) - Name of the function being defined or calledfixed_arg
(any type) - Regular parameter(s) that precede the variadic onevararg
(array type) - One-dimensional array that will collect or expand elementselem_type
(base type) - Element type of the array (text, int, numeric, etc.)array_expression
(array) - Array supplied in a call when using VARIADIC keywordCREATE FUNCTION, ARRAY types, UNNEST, GREATEST, LEAST, DEFAULT parameters
PostgreSQL 8.4
VARIADIC marks the last function parameter as a catch-all array, allowing the function to accept any number of additional arguments without defining multiple overloads.
No. PostgreSQL enforces that only the final parameter may be VARIADIC. Attempting to mark earlier parameters results in an error.
Not necessarily. Supplying a list of values after the fixed parameters automatically packs them into the array. You use the keyword when you want to expand an existing array into separate arguments.
VARIADIC is PostgreSQL-specific. Databases like MySQL, SQL Server, Oracle, and SQLite lack direct support, so code using it is not portable without refactoring.