VECTOR scalar function

Converts a string representation of a vector to a VECTOR value with the specified dimension and coordinate-type.

Read syntax diagramSkip visual syntax diagramVECTOR(vector-string),dimension,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.
Coordinate values can be in any valid numeric format provided it is castable to the coordinate-type (SQLSTATE 22003). The string must comply with the following syntax rules (SQLSTATE 42815):
  • Exactly one left square bracket before the first coordinate.
  • No comma before the first coordinate.
  • Exactly one comma between coordinates.
  • No comma after the last coordinate.
  • Exactly one right square bracket after the last coordinate.
  • A coordinate value cannot be null.
  • The number of coordinate values must equal dimension.
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;