Fix “ERROR 1222 (21000): The used SELECT statements have a different number of columns” when using UNION in MariaDB

When using the UNION operator in MariaDB, you may encounter the following error: “ERROR 1222 (21000): The used SELECT statements have a different number of columns”.

This error occurs when the number of columns returned by each SELECT statement is different.

The way to fix this is to ensure that both SELECT statements return the same number of columns.

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

SQLite JSON_OBJECT()

The SQLite json_object() function returns a well-formed JSON object based on its arguments.

The function accepts zero or more pairs of arguments and returns a well-formed JSON object based on those arguments.

Read more

SQLite JSON()

In SQLite, the json() function converts raw text that looks like JSON into actual JSON.

We pass a JSON string as an argument when we call the function. The json() function then checks that the argument is a valid JSON string and returns a minified version of that JSON string. If the argument is not a well-formed JSON string, then an error is thrown.

However, the json() function was not designed to test whether or not a value is valid JSON. To do that, use the json_valid() function instead.

Read more