Search code examples
sqldatabasepostgresqlvariadic-functionsvariadic

What does VARIADIC declarations mean in PostgreSQL?


In PostgreSQL 9.3.4 release note it says:

Ensure that the planner sees equivalent VARIADIC and non-VARIADIC function calls as equivalent (Tom Lane)

I searched the PostgreSQL manual and couldn't find a definition of what it is.

I found that it's realated to the mode of function argument (IN, OUT, VARIADIC) but I didn't understand what it means? When would I want to use it? What does it mean in terms of performance if function has the VARIADIC property?


Solution

  • Variadic functions are those with an undefined number of arguments, they are present in many programming and query languages.

    In the case of PostgreSQL, you can find an example at http://www.postgresql.org/docs/9.1/static/xfunc-sql.html (35.4.5. SQL Functions with Variable Numbers of Arguments):

    Effectively, all the actual arguments at or beyond the VARIADIC position are gathered up into a one-dimensional array, as if you had written