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.

Read more

Redis SMISMEMBER Command Explained

In Redis, we can use the SMISMEMBER command to find out whether one or more members are in a given set. It’s similar to the SISMEMBER command, except that it allows us to check more than one member at a time.

The SMISMEMBER command was introduced in Redis 6.2.0.

Read more

SQLite JSON_ARRAY_LENGTH()

In SQLite, the json_array_length() function returns the number of elements in a given JSON array.

The array is provided as an argument. If the array is embedded within a larger JSON document, we can use an optional second argument to specify the path to the array.

If the value is not an array, the function returns 0.

Read more

SQLite JSON_ARRAY()

In SQLite, the json_array() function returns a well-formed JSON array based on its arguments.

The function accepts zero or more arguments, and each argument becomes an element in the resulting array.

Read more

How to Return Elements from a JSON Array in MariaDB

MariaDB includes two selectors that enable us to select elements from JSON arrays:

  • [N] selects element number N in the array (for example, [0] to select the first element).
  • [*] selects all elements in the array.

These can be used in a number of JSON functions that are included in MariaDB. The following examples use them with the JSON_EXTRACT() function in order to return selected array elements.

Read more