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.

Continue reading

Fix Error “cannot determine type of empty array” in PostgreSQL

If you’re getting an error that reads “cannot determine type of empty array” in PostgreSQL, it could be that you’re trying to create an empty array without specifying the array type.

It’s impossible to create an array with no type, and so if we want to create an empty array, then we need to specify the type or add items to determine the type.

To fix this issue, either specify the array type for the empty array, or add items to the array.

Continue reading

How ARRAY_FILL() Works in PostgreSQL

In PostgreSQL we can use the array_fill() function to create an array filled multiple instances of a given value.

We pass the value to populate as the first argument, followed by the length of the desired array. The resulting array replicates the first argument as specified by the length in the second argument.

We also have the option of passing a third argument to specify the lower bound values of each dimension of the array.

Continue reading