Skip to main content
Version: V1.0.0

Array constructor functions

Array constructor functions are used to construct new array data types. seekdb currently supports the array() and rb_build() functions and the [] operator.

array

The array() function is used to construct an array data type. The syntax is as follows:

array(elem1, elem2, elem3, ..., elemN)
[elem1, elem2, elem3, ..., elemN]

elem1~elmenN: The input parameters must be of the same data type. For information about the array data types supported by seekdb, 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 (0.001 sec)

rb_build

The rb_build() function is used to convert an array of integers into a highly efficient compressed bitmap (RoaringBitmap). The syntax is as follows:

rb_build(arr)

The input parameters are described as follows:

  • arr: The input must be an array.

The return value is a RoaringBitmap containing all elements of the array.

Constraints:

  • The array cannot contain null elements.
  • If the array is a nested array, recursively extract the base elements from each subarray and insert them into the RoaringBitmap.
  • The RoaringBitmap supports inserting unsigned 64-bit integers (uint64) and signed 32-bit integers (int32). Similar to rb_from_string, negative signed 32-bit integers are first converted to unsigned 32-bit integers before being inserted into the RoaringBitmap. Therefore, the allowed input range for integers is from the minimum value of a signed 32-bit integer to the maximum value of an unsigned 64-bit integer, that is, [INT32_MIN, UINT64_MAX].

Here are some examples:

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 (0.001 sec)
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 (0.001 sec)

[]

The [] operator can also be used to construct array data types. Here is an example:

SELECT [1, 2, 3];
+-----------+
| [1, 2, 3] |
+-----------+
| [1,2,3] |
+-----------+
1 row in set (0.001 sec)