VECTOR_ SUB
On this page
Returns a vector blob from two input vectors by subtracting the second vector from the first vector.
It is a scalar function.
Syntax
VECTOR_SUB(vector_expression, vector_expression)
Arguments
-
vector_
: An expression that evaluates to a vector.expression The vector must be encoded as a blob containing packed single-precision or double-precision floating-point numbers in little-endian byte order.
Return Type
A blob containing packed single-precision floating-point numbers in little-endian byte order.
Remarks
To execute this function, the host processor must support AVX2 instruction set extensions.
Examples
Example: SELECT Using VECTOR_
The following example executes VECTOR_
on a row containing two vectors.HEX()
built-in function is also used to return a readable form of the binary output.
Create a table with two BLOB
-typed columns:
CREATE TABLE vsub_t (a BLOB, b BLOB);
Using the JSON_
INSERT INTO vsub_t VALUES(JSON_ARRAY_PACK('[0.7, 0.2, 1.7]'), JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'));
To demonstrate the contents of the table, use the HEX()
built-in function to return a readable form of the binary data:
SELECT HEX(a), HEX(b) FROM vsub_t;
+--------------------------+--------------------------+
| HEX(a) | HEX(b) |
+--------------------------+--------------------------+
| 3333333FCDCC4C3E9A99D93F | 0000803F0000003F00000040 |
+--------------------------+--------------------------+
Query the table using the VECTOR_
function in a SELECT
statement:
SELECT HEX(VECTOR_SUB(a, b)) FROM vsub_t;
+---------------------------+
| HEX(VECTOR_SUB(a, b)) |
+---------------------------+
| 9A9999BE9A9999BE989999BE |
+---------------------------+
Example: VECTOR_
The following example uses JSON_
as input parameters to the VECTOR_
built-in function.HEX()
built-in function is also used to return a readable form of the binary output:
SELECT HEX(VECTOR_SUB(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]')));+-----------------------------------------------------------------------------------------+| HEX(VECTOR_SUB(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]'))) |+-----------------------------------------------------------------------------------------+| 9A99993E9A99993E9899993E |+-----------------------------------------------------------------------------------------+1 row in set (0.11 sec)
Related Topics
Last modified: March 1, 2023