Skip to main content
Last updated on

INNER_PRODUCT

Description​

Computes the scalar product of two vectors of the same size

Syntax​

INNER_PRODUCT(<array1>, <array2>)

Parameters​

ParameterDescription
<array1>The first vector, the subtype of the input array supports: TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, the number of elements must be consistent with array2
<array2>The second vector, the subtype of the input array supports: TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, the number of elements must be consistent with array1

Return Value​

Returns the scalar product of two vectors of the same size. The return type is FLOAT.

If either input array is NULL, or contains a NULL element, the function returns an error.

Examples​

SELECT INNER_PRODUCT([1, 2], [2, 3]),INNER_PRODUCT([3, 6], [4, 7]);
+-------------------------------+-------------------------------+
| inner_product([1, 2], [2, 3]) | inner_product([3, 6], [4, 7]) |
+-------------------------------+-------------------------------+
| 8 | 54 |
+-------------------------------+-------------------------------+

If an input array is NULL, the function returns an error:

SELECT INNER_PRODUCT(NULL, [1, 2]);
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]First argument for function inner_product cannot be null

If an input array contains a NULL element, the function returns an error:

SELECT INNER_PRODUCT([1, NULL], [1, 2]);
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]First argument for function inner_product cannot have null