VECTOR scalar function
Converts a string representation of a vector to a VECTOR value with the specified dimension and coordinate-type.
The schema is SYSIBM.
-
vector-string
- A VARCHAR or CLOB expression representing a VECTOR value. The string representation of a VECTOR value is a comma-separated list of coordinates delimited by square brackets. Any number of blank characters are allowed before and after square brackets, commas and coordinates. dimension
- An integer literal that indicates the dimension of the resulting vector value. The dimension value must be from 1 to the maximum for the specified coordinate-type (SQLSTATE 42815), and it must equal the number of coordinates in the vector string (SQLSTATE 42815). coordinate-type
-
- REAL or FLOAT32: single-precision, 4-byte floating point.
- INT8: 1-byte integer.
Result
The result of the function is a vector value with the specified dimension and coordinate-type. If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.
Usage notes
The VECTOR function is required for converting vector data from a human-readable string format,
such as '[0.123, -0.456, 0.789]'
, into a binary format that can be efficiently
stored in a VECTOR column. This function allows users to prepare vector data for efficient storage
and processing within Db2 by converting it into a compact binary format.
Examples
The following example shows the command syntax for running a SQL update statement that uses the
VECTOR
scalar function to convert a vector string into a VECTOR value and store it
in a Db2
table:UPDATE VECTOR_TB SET RVECTOR = VECTOR('[0.123, -0.456, 0.789]', 3, REAL) WHERE ID = 1;