An array constructor function constructs an array object. OceanBase Database supports the array() array constructor function and the [] operator.
array()
The array() function constructs an array object. The syntax is as follows:
array(elem1, elem2, elem3, ..., elemN)
[elem1, elem2, elem3, ..., elemN]
elem1 to elmenN: The input arguments must be of the same data type. For more information about supported array data types, see Overview of array data types.
Here is an example:
SELECT array(1, 2, 3);
+----------------+
| array(1, 2, 3) |
+----------------+
| [1,2,3] |
+----------------+
1 row in set
rb_build
The rb_build() function is used to convert an array of integers into a RoaringBitmap. The syntax is as follows:
rb_build(arr)
The parameters are described as follows:
arr: The type of the input parameter must be an array.
The return value is a RoaringBitmap that contains all the elements of the array.
The following constraints apply:
- The array cannot contain null elements.
- If the array is a nested array, the function recursively extracts the base elements of each subarray and inserts them into the RoaringBitmap.
- The RoaringBitmap supports the insertion of unsigned 64-bit integers (uint64) and signed 32-bit integers (int32). Similar to the behavior of rb_from_string, a negative signed 32-bit integer is first converted to an unsigned 32-bit integer before being inserted into the RoaringBitmap. Therefore, the allowed integer range is from the minimum value of signed 32-bit integers to the maximum value of unsigned 64-bit integers, that is,
[INT32_MIN, UINT64_MAX].
Here is an example:
SELECT rb_to_string(rb_build([1.2]));
ERROR 5083 (22000): Invalid data type for the operation
SELECT rb_to_string(rb_build([0,1,2]));
+---------------------------------+
| rb_to_string(rb_build([0,1,2])) |
+---------------------------------+
| 0,1,2 |
+---------------------------------+
1 row in set
SELECT rb_to_string(rb_build([[0,1],[2],[2,3]]));
+-------------------------------------------+
| rb_to_string(rb_build([[0,1],[2],[2,3]])) |
+-------------------------------------------+
| 0,1,2,3 |
+-------------------------------------------+
1 row in set
[]
You can also use the [] operator to construct an array object. Here is an example:
SELECT [1, 2, 3];
+-----------+
| [1, 2, 3] |
+-----------+
| [1,2,3] |
+-----------+
1 row in set