JSON_ ARRAY_ PACK
On this page
Converts a JSON array of zero or more floating point numbers to an encoded blob.
It is a scalar function.
Syntax
JSON_ARRAY_PACK('[float [, ...]]')
Arguments
A JSON array.
Return Type
A blob containing packed single-precision floating-point numbers in little-endian byte order.
Warning
Beginning with 8.
Remarks
JSON_
can be used with other vector built-in functions, namely DOT_
, VECTOR_
, VECTOR_
,VECTOR_
, and EUCLIDEAN_
.JSON_
is appropriately formatted for use as an input parameter to these functions.
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
Example: Inserting Data Using JSON_
The following example inserts data into a table with a column of the BLOB
data type.HEX()
built-in function is also used to return a readable form of the binary output:
CREATE TABLE jp_t (b blob);INSERT INTO jp_t VALUES (JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'));
SELECT HEX(b) FROM jp_t;
+--------------------------+
| HEX(b) |
+--------------------------+
| 0000803F0000003F00000040 |
+--------------------------+
You can also use the suffix to specify the data type as follows:
INSERT INTO jp_t VALUES (JSON_ARRAY_PACK_I16('[1.0, 0.5, 2.0]'));
SELECT HEX(b) FROM jp_t;
+--------------+
| HEX(b) |
+--------------+
| 010001000200 |
+--------------+
Example: Using JSON_
The following example uses JSON_
for input parameters to the DOT_
built-in function:
SELECT DOT_PRODUCT(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'));
+-------------------------------------------------------------------------------------+
| DOT_PRODUCT(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[1.0, 0.5, 2.0]')) |
+-------------------------------------------------------------------------------------+
| 5.25 |
+-------------------------------------------------------------------------------------+
Example: Using JSON_
The following example uses JSON_
for input parameters to the VECTOR_
built-in function.HEX()
built-in function is also used to return a readable form of the binary output:
SELECT HEX(VECTOR_SUB(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]')));
+-----------------------------------------------------------------------------------------+
| HEX(VECTOR_SUB(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]'))) |
+-----------------------------------------------------------------------------------------+
| 9A99993E9A99993E9899993E |
+-----------------------------------------------------------------------------------------+
Example: Using JSON_
The following example uses JSON_
for input parameters to the EUCLIDEAN_
built-in function:
SELECT EUCLIDEAN_DISTANCE(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]'));
+--------------------------------------------------------------------------------------------+
| EUCLIDEAN_DISTANCE(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]')) |
+--------------------------------------------------------------------------------------------+
| 0.5196152239171921 |
+--------------------------------------------------------------------------------------------+
Related Topics
Last modified: March 21, 2024