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

The VECTOR_SUBVECTOR() function derives a vector expression from another vector expression.

It is a scalar function.

Syntax

VECTOR_SUBVECTOR(vector_expression, start_position, length)

Arguments

  • vector_expression: An expression that evaluates to a vector. The input expression can use the VECTOR data type or a BLOB-encoded vector.

  • start_position: A 0-indexed number to determine where to start count. 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_SUBVECTOR() returns a VECTOR expression.

  • If the input expression is of type BLOB, VECTOR_SUBVECTOR() returns a 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. Omitting the suffix from the function is equivalent to suffixing it with _F32. All operations are done using the specified data type. The following table lists the suffixes and their data type.

Suffix

Data Type

_I8

8-bit signed integer

_I16

16-bit signed integer

_I32

32-bit signed integer

_I64

64-bit signed integer

_F32

32-bit floating-point number (IEEE standard format)

_F64

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_SUBVECTOR() returns the selected subvector as a VECTOR expression. VECTOR_SUBVECTOR() accepts VECTOR inputs of all supported element types, including F16 (for example, VECTOR(5, F16)). For readable output, set vector_type_project_format 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:

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK

Try Out This Notebook to See What’s Possible in SingleStore

Get access to other groundbreaking datasets and engage with our community for expert advice.