Fix “function generate_subscripts(text[], integer, integer) does not exist” in PostgreSQL

If you’re getting a PostgreSQL error that reads something like “function generate_subscripts(text[], integer, integer) does not exist“, it’s probably because your third argument is of the wrong type when using the generate_subscripts() function.

The above error specifically implies that an integer was passed as the third argument, but it must be a boolean value.

The third argument of the generate_subscripts() function is optional, but if passed, it must be a boolean expression.

To fix this error, either pass a boolean value as the third argument, or eliminate the third argument altogether.

Continue reading

Fix Error “could not determine polymorphic type because input has type unknown” when using generate_subscripts() in PostgreSQL

If you’re getting an error that reads “could not determine polymorphic type because input has type unknown” when using the generate_subscripts() function in PostgreSQL, it’s probably because your first argument is of the wrong type.

The generate_subscripts() function requires an array as its first argument. Passing a non-array value will result in an error. The actual error can vary, depending on the argument you pass, but regardless, the error is usually due to a non-array argument being passed.

To fix this error, be sure to pass an array as the argument when calling generate_subscripts().

Continue reading

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.

Continue reading

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.

Continue reading

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.

Continue reading

5 Ways to Enable Vertical Output in psql

When we use psql to write SQL queries in PostgreSQL, we’ll usually see the results presented as a table, with columns displayed vertically and rows running horizontally. But it is possible to change this so that the columns are displayed horizontally and the rows run vertically.

This can be useful for when the number of columns causes the results to be wider than our psql display, and may cause the rows to wrap to the next line.

Here are five ways we can change the display to vertical output, otherwise known as expanded display.

Continue reading

How to “Unhide” a GIPK in MySQL

In MySQL, GIPKs are invisible by definition. GIPK stands for generated invisible primary key, and it’s basically an invisible column automatically created by MySQL with a primary key constraint.

However, just because GIPKs are automatically created invisible, it doesn’t mean that we can’t “unhide” them – or make them visible.

We can make a GIPK visible just as we would make any other invisible column visible – use the ALTER TABLE statement to set it to VISIBLE.

Continue reading