JSON_ ARRAY_ UNPACK
Warning
SingleStore 9.0 gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 8.9 is recommended for production workloads, which can later be upgraded to SingleStore 9.0.
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 the ju_
table.
CREATE TABLE ju_t (x BLOB, y BLOB);INSERT INTO ju_t VALUES (JSON_ARRAY_PACK('[12.1, 6.4]'), JSON_ARRAY_PACK('[8.6,9.2]'));INSERT INTO ju_t VALUES (JSON_ARRAY_PACK('[5.2, 11.7]'), JSON_ARRAY_PACK('[4.6,7.3]'));
Querying Rows Using JSON_ ARRAY_ UNPACK
The following example queries the t
table using the JSON_
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 the t
table are 32-bit floating point numbers, because no suffix was specified with the JSON_
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] |
+-------------------------+-------------------------+
Related Topics
Last modified: March 21, 2024