A Quick Overview of ARRAY_NDIMS() in PostgreSQL

In PostgreSQL the array_ndims() function returns the number of dimensions of an array. We pass the array to the function, and it returns an integer of the number of dimensions in the array.

This function is not to be confused with the array_dims() function, which returns a more detailed text representation of the dimensions in the array.

Read more

Fix “sample size must be between…” Error when using array_sample() in PostgreSQL

If you’re getting an error that starts with “sample size must be between…” when using the array_sample() function in PostgreSQL, it’s probably because your second argument is either a negative value, or it’s larger than the number of elements in the array.

The second argument must be no less than zero, and it can’t be any larger than the number of elements in the array.

To fix this error, be sure that your second argument is greater than zero and less than or equal to the number of elements in the array at the first argument.

Read more

Understanding ARRAY_DIMS() in PostgreSQL

In PostgreSQL we can use the array_dims() function to return information about the dimensions in an array. The function accepts the array in question, and it returns a text representation of the array’s dimensions.

This function is not to be confused with the array_ndims() function, which simply returns the number of dimensions in an array.

Read more

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.

Read more

Fix “invalid input syntax for type integer…” When Using array_sample() in PostgreSQL

If you’re getting an error that reads “invalid input syntax for type integer…” when using the array_sample() function in PostgreSQL, it’s probably because your second argument is not an integer.

The second argument for this function must be an integer.

To fix this error, be sure that your second argument to array_sample() is an integer.

Read more