Skip to content

SUBVECTOR()

Function description

The SUBVECTOR() function is used to extract subvectors from vectors.

Function Syntax

> SUBVECTOR(vec, pos, len)

Parameter definition

Parameters Description
vec Required parameters. Extract the source vector of sub-vectors from
pos Required parameters. The location where the extraction begins. The first position in the vector is 1, and if pos is positive, the function is extracted from the beginning of the vector. If pos is negative, the extraction starts at the end of the vector.
len Optional parameters. The number of dimensions to be extracted. The default subvectors start from position pos to the end of the vector. If len is less than 1, an empty vector is returned.

Example

mysql> SELECT SUBVECTOR("[1,2,3]", 2);
+---------------------------+
| subvector([1,2,3], 2) |
+---------------------------+
| [2, 3] |
+---------------------------+
1 row in set (0.01 sec)

mysql> SELECT SUBVECTOR("[1,2,3]",-1,1);
+--------------------------------+
| subvector([1,2,3], -1, 1) |
+--------------------------------+
| [3] |
+--------------------------------+
1 row in set (0.00 sec)

mysql> SELECT SUBVECTOR("[1,2,3]",-1,0);
+--------------------------------+
| subvector([1,2,3], -1, 0) |
+--------------------------------+
| [] |
+--------------------------------+
1 row in set (0.00 sec)