Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does VARIADIC declarations mean in PostgreSQL?

Tags:

sql

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?

like image 584
Johnathan Avatar asked Nov 19 '15 11:11

Johnathan


2 Answers

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

like image 88
Pablo Francisco Pérez Hidalgo Avatar answered Oct 05 '22 12:10

Pablo Francisco Pérez Hidalgo


When you are not sure about the number of parameters then we use Variadic.

You can refer VARIADIC FUNCTIONS IN POSTGRESQL for details.

See the wiki about Variadic functions:

In computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages.

like image 43
Rahul Tripathi Avatar answered Oct 05 '22 12:10

Rahul Tripathi