Important
The SingleStore 10 release candidate (RC) gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 9.0 is recommended for production workloads, which can later be upgraded to SingleStore 10.
VECTOR_ SUBVECTOR
On this page
The VECTOR_ function derives a vector expression from another vector expression.
It is a scalar function.
Syntax
VECTOR_SUBVECTOR(vector_expression, start_position, length)
Arguments
-
vector_: An expression that evaluates to a vector.expression The input expression can use the VECTORdata type or aBLOB-encoded vector. -
start_: A 0-indexed number to determine where to start count.position A positive index counts from the beginning of the vector. A negative index counts from the end of the vector. -
length: Length of required subvector.
Return Type
-
If the input expression is of type
VECTOR,VECTOR_returns aSUBVECTOR() VECTORexpression. -
If the input expression is of type
BLOB,VECTOR_returns aSUBVECTOR() BLOB.
Remarks
If the input is NULL, NULL will be returned.
You can specify the data type of the vector elements in which this operation is performed on the vector by adding a suffix to the function._.
|
Suffix |
Data Type |
|---|---|
|
|
8-bit signed integer |
|
|
16-bit signed integer |
|
|
32-bit signed integer |
|
|
64-bit signed integer |
|
|
32-bit floating-point number (IEEE standard format) |
|
|
64-bit floating-point number (IEEE standard format) |
Examples
CREATE TABLE vsv_t (x BLOB);INSERT INTO vsv_t VALUES (JSON_ARRAY_PACK('[1,2,3,4,5]'));
SELECT JSON_ARRAY_UNPACK (VECTOR_SUBVECTOR(x,2,2)) AS x from vsv_t;
+-------+
| x |
+-------+
| [3,4] |
+-------+SELECT JSON_ARRAY_UNPACK (VECTOR_SUBVECTOR(x,-2,2)) AS x from vsv_t;
+-------+
| x |
+-------+
| [4,5] |
+-------+How to Use the Vector Data Type
When the input expression uses the VECTOR data type, VECTOR_ returns the selected subvector as a VECTOR expression.VECTOR_ accepts VECTOR inputs of all supported element types, including F16 (for example, VECTOR(5, F16)). For readable output, set vector_ to JSON.
Example
SET @pos = '[1,2,3,4]':>VECTOR(4);SELECT VECTOR_SUBVECTOR(@pos, 1, 2):>VECTOR(2);+----------------------------------+| VECTOR_SUBVECTOR(@pos, 1, 2):>VECTOR(2) |+----------------------------------+| [2,3] |+----------------------------------+
Last modified: