Variadic function support
I have a postgres function with a signature like so:
create or replace function do_stuff(variadic ids uuid[]) returns int
In my EF data context I've defined a DbFunction method like so:
[DbFunction("do_stuff")]
public static int DoStuff(Guid[] ids)
{
throw new Exception("Not implemented in code; this is a DB function.");
}
When I invoke it, however, I get an exception:
MessageText: function public.do_stuff(uuid[]) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Ok, so passing an array to a variadic seems to be an invalid cast. What, then, is the correct way to invoke this function?
FYI, I worked around the issue by getting rid of the variadic, so that the signature is simply:
create or replace function do_stuff(ids uuid[]) returns int
But I'd still be interested to know how to do it with a variadic.
Interesting... You should be able to define multiple overloads of DoStuff, with different numbers of parameters (an overload with one Guid parameter, another with two Guid parameters), and transparently map those to a PostgreSQL variadic function. That's obviously not ideal, as the number of parameters is totally unknown.
Support for actual variadic functions would need to be added - I'm not yet sure if it can be done in the Npgsql provider or if it would require EF Core changes as well (note that AFAIK only PostgreSQL supports variadic functions). One small note, is that for parameters we'd want to generate SELECT mleast(VARIADIC ARRAY[10, -1, 5, 4.4]) (note the VARIADIC keyword in the invocation, see the PG docs). This is to make sure that array parameters are passed as is and not expanded out to constants - that would result in different SQLs per array, which would be bad for perf.
/cc @smitpatel @ajcvickers