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

If you’re getting an error that reads “function array_sample(integer, integer) does not exist” when using the array_sample() function in PostgreSQL, it’s probably because your first argument is not an array. In particular, this specific error message implies that the first argument is an integer.

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 an integer.

Continue reading

Create a Generated Invisible Primary Key (GIPK) in MySQL

MySQL 8.0.30 introduced generated invisible primary keys (GIPKs), which are primary keys that are automatically created whenever we create a table without explicitly defining a primary key.

GIPKs only work with the InnoDB storage engine, and they only work when we have GIPKs enabled.

In this article, I check whether or not GIPKs are enabled on my system, I then enable GIPKs, and finally I create a table with a GIPK.

Continue reading

Remove the Comment from an Event in MySQL

When we create a scheduled event in MySQL we have the option of using the COMMENT clause to add a comment to the event. Comments can be a handy addition that help explain what the event does, why it was created, etc.

So it’s probably quite rare that we would want to remove the comment from an event. But in the event that we do (pun intended!), we can simply update the event with a blank comment.

Continue reading

SQLite’s json_valid() Now Accepts an Argument that Defines What “Valid” Means

SQLite’s json_valid() function allows us to check whether a JSON string is well formed or not.

Prior to SQLite 3.45.0 the json_valid() function only accepts one argument – the value to check. However, from SQLite 3.45.0 (released on 15 January 2024), we can now provide an optional second argument to define what valid – or “well formed” – means.

Continue reading