VECTOR_ SORT
On this page
Sorts the elements in the vector expression in ascending or descending order.
If no order specified, ascending order is the default.
Syntax
VECTOR_SORT(vector_expression [,'asc'|'desc'])
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. -
asc
ordesc
: The sort order in which the vector will be returned.Asc
means ascending order.Desc
means descending order.Asc
is the default.
Return Type
A blob containing packed single-precision floating-point numbers in little-endian byte order.
Remarks
A vector can be of any length, but the input blob length must be divisible by the packed vector element size (1, 2, 4 or 8 bytes, depending on the vector element).
You can specify the datatype of the vector elements in which this operation is performed on the vector by adding a suffix to the function._
.
Suffix |
Datatype |
---|---|
|
8-bit signed integer |
|
16-bit signed integer |
|
32-bit signed integer |
|
64-bit signed integer |
|
32-bit floating-point number (IEEE standard format) |
|
64-bit floating-point number (IEEE standard format) |
Examples
CREATE TABLE vs_t (x BLOB);INSERT INTO vs_t VALUES (JSON_ARRAY_PACK('[4,3,1,5,2]'));
SELECT JSON_ARRAY_UNPACK (VECTOR_SORT(x)) AS x from vs_t;
+-------------+
| x |
+-------------+
| [1,2,3,4,5] |
+-------------+
SELECT JSON_ARRAY_UNPACK (VECTOR_SORT(x,'asc')) AS x from vs_t;
+-------------+
| x |
+-------------+
| [1,2,3,4,5] |
+-------------+
SELECT JSON_ARRAY_UNPACK (VECTOR_SORT(x,'desc')) AS x from vs_t;
+-------------+
| x |
+-------------+
| [5,4,3,2,1] |
+-------------+
Last modified: February 28, 2023