Fix “function array_shuffle(integer) does not exist” in PostgreSQL

If you’re getting an error that reads “function array_shuffle(integer) does not exist” when using the array_shuffle() function in PostgreSQL, it’s probably because the argument you’re passing to the function is not an array.

More specifically, this error message implies that you’re passing an integer. The same error can occur when passing other non-array types (such as numeric), but the solution is the same.

The argument for this function must be an array.

To fix this error, replace the integer value with an array value when calling the array_shuffle() function.

Example of Error

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

SELECT array_shuffle( 1 );

Result:

ERROR:  function array_shuffle(integer) does not exist
LINE 1: SELECT array_shuffle( 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 argument to array_shuffle() but it doesn’t accept an integer. It must be an array.

Solution

We can fix the problem by passing an array instead of an integer:

SELECT array_shuffle( ARRAY[ 'Cat', 'Dog', 'Bird' ] );

Result:

 array_shuffle  
----------------
{Bird,Cat,Dog}

This time the function worked without error.