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

If you’re getting a PostgreSQL error that reads “function generate_subscripts(integer, 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 an integer, but we’d get a similar error when passing a numeric argument.

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, 1);

Result:

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

Here I passed an integer as the first argument to generate_subscripts() but it doesn’t accept an integer as the first argument. The second argument can (and must) be an integer, but 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.