Fix Error “function generate_subscripts(numeric, integer) does not exist” in PostgreSQL

If you’re getting a PostgreSQL error that reads “function generate_subscripts(numeric, integer) does not exist“, it’s probably because your first argument is not an array. This specific error message implies that the first argument is a numeric value, but we’d get a similar error when passing an integer.

The first argument for this function must be an array.

To fix this error, be sure that your first argument to generate_subscripts() is an array.

Example of Error

Here’s an example of code that produces the error:

SELECT generate_subscripts(1.5, 1);

Result:

ERROR:  function generate_subscripts(numeric, integer) does not exist
LINE 1: SELECT generate_subscripts(1.5, 1);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

Here I passed a numeric value as the first argument to the function but it doesn’t accept numeric values as the first argument. The first argument must be an array of any type.

Solution

We can fix the problem by ensuring that the first argument is an array.

Example:

SELECT generate_subscripts('{"Flower","Leaf","Trunk"}'::text[], 1);

Result:

 generate_subscripts 
---------------------
1
2
3

This time the function worked without error.