Add Optional Variadic Invocation Explanation to 35.4.5 (xfunc-sql)

From: David Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "pgsql-docs(at)postgresql(dot)org" <pgsql-docs(at)postgresql(dot)org>
Subject: Add Optional Variadic Invocation Explanation to 35.4.5 (xfunc-sql)
Date: 2014-12-19 21:33:19
Message-ID: CAKFQuwaomm_7N9Y_9pd43eXgMyQxzogtjD4CJxjaxk05QsF1pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

CREATE FUNCTION varfunc (fixed1 text, VARIADIC vars text[]) [...]

SELECT varfunc('text fixed 1'); -- error: function signature not found;
thus the number of supplied variadic values must be >= 1

This:

http://www.postgresql.org/docs/9.4/static/xfunc-sql.html

Describes how to invoke a function defined with VARIADIC with an actual
array as input instead of supplying ONE-or-more individual arguments to the
call.

AFAICS the only way to get the called function to see an empty array is to
call it like:

SELECT varchar('text fixed 1', VARIADIC ARRAY[]::text[])

While this is a logical solution to the problem, given the above knowledge,
it would be nice if both points were made explicitly in the documentation
in the section linked above.

Existing: "Sometimes it is useful to be able to pass an already-constructed
array to a variadic function; this is particularly handy when one variadic
function wants to pass on its array parameter to another one."

Change that to:

"Sometimes it is useful to be able to pass an already-constructed array to
a variadic function."
<move existing sample to here>
"While this is particularly handy when one variadic function wants to pass
on its array parameter to another[/cut] it is required if you wish to
invoke the function without passing any optional arguments. The following
example's first attempt to omit the variadic argument fails since the
planner looks for a different function signature. By using the variadic
invocation the second attempt succeeds. The alternative is to define an
overloaded function without a VARIADIC parameter but with the same
non-optional ones."
<better example maybe...but show/explain the two queries above>

Thoughts? Am I missing something?

David J.

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message David Johnston 2014-12-20 01:52:42 libpq "service" parameter not documented as not allowed inside a pg_service file
Previous Message Martin Steer 2014-12-18 13:35:07 Re: warning about console code page on starting psql