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

If you’re getting an error that reads “function array_sample(numeric, integer) does not exist” when using the array_sample() function in PostgreSQL, it’s probably because your first argument is a numeric type instead of an array.

The first argument for this function must be an array.

To fix this error, be sure that your first argument to array_sample() is an array, not a numeric value.

Continue reading

How to Create a MySQL Event Only if it Doesn’t Already Exist

In MySQL we can use the CREATE EVENT statement to create scheduled events. As with many CREATE ... statements, we have the option of using the IF NOT EXISTS clause to specify that the object should only be created if it doesn’t already exist.

Of course, we wouldn’t normally be trying to create an event if we know that it already exists. But there may be times where we’re not sure, and we want our code to handle this scenario without throwing an error if an event with the same name already exists. This is common when creating scripts that are designed to be run across multiple environments. That’s where the IF NOT EXISTS clause can come in handy.

Continue reading

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.

Continue reading

Fix “source array too small” When Updating an Array in PostgreSQL

If you’re getting an error that reads “source array too small” when updating an array in PostgreSQL, it’s probably because you’re passing a slice that’s smaller than your specified range. For example, if you specify a range that covers four elements but provide an array that contains just three elements, then you’d get this error.

To fix the error, be sure to provide an an array that contains at least as many elements as are specified in the range.

Continue reading

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

If you’re getting an error that reads “function array_shuffle(integer, 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.

Actually, the error message implies that you’re passing multiple integer values (two in this case, but it could be more), separated by a comma. Perhaps you’re trying to pass an array of integers, but you haven’t provided them in an array. Or perhaps you’re passing the wrong column or variable. Either way, the argument for this function must be an array.

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

Continue reading

Fix Error “op ANY/ALL (array) requires array on right side” in PostgreSQL

If you’re getting a PostgreSQL error that reads “op ANY/ALL (array) requires array on right side” it’s probably because you’re passing a non array to the ANY() or ALL() construct.

These constructs require an array to be included in the parentheses, and so passing a non array returns an error.

To fix this issue, be sure to pass an array when using these functions.

Continue reading

Fix Error “date field value out of range” when using make_date() in PostgreSQL

If you’re getting an error that reads ‘date field value out of range‘ in PostgreSQL while using the make_date() function, it’s probably because one or more of the date parts you’re providing is out of range for that date part.

It’s possible that you’ve got the month and day in the wrong order.

To fix this issue, be sure that each date part you provide is within the valid range for that date part. It may be that all you need to do is switch the day and the month around.

Continue reading