2

I'm using plpython3u to process a result that contains an arbitrary number of columns each of which hold an array (of varying lengths > 0). In python, I'd be expecting to process this data as a multidimensional array but I'm having trouble getting it from Postgres into my function.

The function declaration I am using looks like this:

CREATE OR REPLACE FUNCTION is_set_cover_possible(VARIADIC args numeric[][])

The problem is that when I try

SELECT is_set_cover_possible(ARRAY[1,2],ARRAY[1,2]);

I get:

No function matches the given name and argument types. You might need to add explicit type casts.

If I pass in (ARRAY[1,2]) the function returns a result without failing so it seems postgres can't handle the multidimensional declaration above.

So, if it's actually possible: How do I declare the function so as to receive a list of arrays?

jcuenod
  • 55,835
  • 14
  • 65
  • 102

1 Answers1

2

You cannot to do it. Arguments used as variadic arguments cannot be arrays.

Implementation of variadic arguments was at time when this was not possible technically. Now it is possible, but nobody implemented it.

Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94
  • Is it a good solution to overload the function with a large number of possible arguments (and handle the case of too many arguments separately)? – jcuenod Jun 17 '19 at 12:24
  • I don't see any benefit of this. I don't know your use case, but variadic parameters are little bit syntactic sugar - you can pass multidimensional array instead. The most simple solution is usually the best. – Pavel Stehule Jun 17 '19 at 15:24
  • The advantage is mainly that I don't know how many parameters there will be. The query is constructed dynamically and the arrays vary in length (I haven't tested this but it seems that pg has issues with multidimensional arrays of different lengths). – jcuenod Jun 18 '19 at 20:27
  • you can use array of rows containing arrays – Pavel Stehule Jun 19 '19 at 04:21