If you’re getting an error that reads “could not determine polymorphic type because input has type unknown” when using the generate_subscripts()
function in PostgreSQL, it’s probably because your first argument is of the wrong type.
The generate_subscripts()
function requires an array as its first argument. Passing a non-array value will result in an error. The actual error can vary, depending on the argument you pass, but regardless, the error is usually due to a non-array argument being passed.
To fix this error, be sure to pass an array as the argument when calling generate_subscripts()
.
Example of Error
Here’s an example of code that produces the error:
SELECT generate_subscripts(NULL, 1);
Result:
ERROR: could not determine polymorphic type because input has type unknown
I got the error because my argument wasn’t an array. In this case it was NULL
. The “polymorphic type” part refers to the fact that the generate_subscripts()
function is a polymorphic function. That is, it accepts a polymorphic type as an argument. In this case the first argument can be any array type.
Polymorphic types enable a single function definition to operate on many different data types, with the specific data type(s) being determined by the data types actually passed to it in a particular call.
Solution
We can fix the problem by passing an array to the function:
SELECT generate_subscripts('{"Flower","Leaf","Trunk"}'::text[], 1);
Result:
generate_subscripts
---------------------
1
2
3
This time the function worked without error. That’s because we passed an array this time.