JSON_ ARRAY_ UNPACK
On this page
Converts an encoded blob representing a vector to a JSON array representing the same vector.
It is a scalar function.
Syntax
JSON_ARRAY_UNPACK(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 JSON array of zero or more floating point numbers.
Warning
Beginning with 8.
Remarks
A vector can be of any length, but blob lengths must be divisible by 4 bytes (or 8 bytes, depending on the data type specified).
You can specify the data type of the vector elements in which this operation is performed on the vector by adding a suffix to the function._
.
Suffix | Data Type |
---|---|
| 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
The following examples use theju_
table.
CREATETABLE ju_t(xBLOB, yBLOB);INSERTINTO ju_tVALUES(JSON_ARRAY_PACK('[12.1, 6.4]'), JSON_ARRAY_PACK('[8.6,9.2]'));INSERTINTO ju_tVALUES(JSON_ARRAY_PACK('[5.2, 11.7]'), JSON_ARRAY_PACK('[4.6,7.3]'));
Querying Rows Using JSON_ ARRAY_ UNPACK
The following example queries thet
table using theJSON_
function:
SELECT JSON_ARRAY_UNPACK(x)"x", JSON_ARRAY_UNPACK(y)"y"from ju_t;
+-------------------------+-------------------------+| x | y |+-------------------------+-------------------------+| [12.1000004,6.4000001] | [8.60000038,9.19999981] || [5.19999981,11.6999998] | [4.5999999,7.30000019] |+-------------------------+-------------------------+
Typecasting the Data Type using Suffixes
The values inserted in thet
table are 32-bit floating point numbers, because no suffix was specified with theJSON_
function.
SELECT JSON_ARRAY_UNPACK_I32(x)"x", JSON_ARRAY_UNPACK_I32(y)"y"from ju_t;
+-------------------------+-------------------------+| x | y |+-------------------------+-------------------------+| [1094818202,1087163597] | [1091148186,1091777331] || [1084647014,1094398771] | [1083388723,1089051034] |+-------------------------+-------------------------+