Skip to main content

Array Functions

All LIST functions work with the ARRAY data type. Additionally, several ARRAY-native functions are also supported.

Array-Native Functions

FunctionDescription
array_cosine_distance(array1, array2)Computes the cosine distance between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.
array_cosine_similarity(array1, array2)Computes the cosine similarity between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.
array_cross_product(array, array)Computes the cross product of two arrays of size 3. The array elements cannot be NULL.
array_distance(array1, array2)Computes the distance between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.
array_dot_product(array1, array2)Alias for array_inner_product.
array_inner_product(array1, array2)Computes the inner product between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.
array_negative_dot_product(array1, array2)Alias for array_negative_inner_product.
array_negative_inner_product(array1, array2)Computes the negative inner product between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.
array_value(arg, ...)Creates an ARRAY containing the argument values.

array_cosine_distance(array1, array2)

Computes the cosine distance between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.

Query
SELECT array_cosine_distance(array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT), array_value(2.0::FLOAT, 3.0::FLOAT, 4.0::FLOAT)) AS array_cosine_distance;
Result
 array_cosine_distance-----------------------           0.007416606

array_cosine_similarity(array1, array2)

Computes the cosine similarity between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.

Query
SELECT array_cosine_similarity(array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT), array_value(2.0::FLOAT, 3.0::FLOAT, 4.0::FLOAT)) AS array_cosine_similarity;
Result
 array_cosine_similarity-------------------------               0.9925834

array_cross_product(array, array)

Computes the cross product of two arrays of size 3. The array elements cannot be NULL.

Query
SELECT array_cross_product(array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT), array_value(2.0::FLOAT, 3.0::FLOAT, 4.0::FLOAT)) AS array_cross_product;
Result
 array_cross_product--------------------- {-1,2,-1}

array_distance(array1, array2)

Computes the distance between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments.

Query
SELECT array_distance(array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT), array_value(2.0::FLOAT, 3.0::FLOAT, 4.0::FLOAT)) AS array_distance;
Result
 array_distance----------------      1.7320508

array_inner_product(array1, array2)

Computes the inner product between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments. Alias: array_dot_product.

Query
SELECT array_inner_product(array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT), array_value(2.0::FLOAT, 3.0::FLOAT, 4.0::FLOAT)) AS array_inner_product;
Result
 array_inner_product---------------------                  20

array_negative_inner_product(array1, array2)

Computes the negative inner product between two arrays of the same size. The array elements cannot be NULL. The arrays can have any size as long as the size is the same for both arguments. Alias: array_negative_dot_product.

Query
SELECT array_negative_inner_product(array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT), array_value(2.0::FLOAT, 3.0::FLOAT, 4.0::FLOAT)) AS array_negative_inner_product;
Result
 array_negative_inner_product------------------------------                          -20

array_value(arg, ...)

Creates an ARRAY containing the argument values.

Query
SELECT array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT) AS array_value;
Result
 array_value------------- {1,2,3}

This page contains: