Array output functions
Array output functions are used to select the output format of array data. For example, you can output each element of the array data as a string and separate the elements with commas. The array output functions supported by seekdb include array_to_string().
array_to_string
The array_to_string() function converts an array to a string. Specifically, it prints all the base elements of the array into a string based on the specified delimiter and null element symbol. If the array is a nested array, it recursively prints its non-empty subarrays. It is not completely the inverse function of string_to_array(). The syntax is as follows:
array_to_string(arr1, delimiter[, null_str])
The input parameters are described as follows:
arr1must be an array type.delimiterspecifies the delimiter, which can be a character type, including Char and Varchar.null_str(optional) specifies the null element symbol, which can be a character type, including Char and Varchar. If this parameter is not specified, NULL elements and their corresponding delimiters will not be printed.
The return result is a string of Text type.
Here are some examples:
SELECT array_to_string([1,2,NULL,3], '-', 'N');
+-----------------------------------------+
| array_to_string([1,2,NULL,3], '-', 'N') |
+-----------------------------------------+
| 1-2-N-3 |
+-----------------------------------------+
1 row in set (0.001 sec)
SELECT array_to_string([1,2,NULL,3], 'and');
+--------------------------------------+
| array_to_string([1,2,NULL,3], 'and') |
+--------------------------------------+
| 1and2and3 |
+--------------------------------------+
1 row in set (0.001 sec)
SELECT array_to_string([["hello", "world"], ["hi", "what"]], '-');
+------------------------------------------------------------+
| array_to_string([["hello", "world"], ["hi", "what"]], '-') |
+------------------------------------------------------------+
| hello-world-hi-what |
+------------------------------------------------------------+
1 row in set (0.001 sec)
SELECT array_to_string([["hello", "world"], ["hi", "what"], NULL], '-', 'N');
+-----------------------------------------------------------------------+
| array_to_string([["hello", "world"], ["hi", "what"], NULL], '-', 'N') |
+-----------------------------------------------------------------------+
| hello-world-hi-what-N |
+-----------------------------------------------------------------------+
1 row in set (0.001 sec)