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

If you’re getting an error that reads “function array_shuffle(numeric) 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 a numeric type. The same error can occur when passing other non-array types (such as integer), but the solution is the same.

The argument for this function must be an array.

To fix this error, replace the numeric 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.5 );

Result:

ERROR:  function array_shuffle(numeric) does not exist
LINE 1: SELECT array_shuffle( 1.5 );
^
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 argument to array_shuffle() but it doesn’t accept that type. It only accepts an array of any type.

Solution

We can fix the problem by passing an array instead of a numeric value:

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

Result:

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

This time the function worked without error.