Collections:
JSON_STORAGE_FREE() - Free Space in JSON Value
How to obtain the free space size in a JSON table column using the JSON_STORAGE_FREE() function?
✍: FYIcenter.com
JSON_STORAGE_FREE(json) is a MySQL built-in function that
returns the free space size in a JSON table column.
Free space occurs when JSON table column is partially updated with less data. For example:
CREATE TABLE jtable (jcol JSON);
INSERT INTO jtable VALUES ('{"a": 1000, "b": "FYIcenter", "c": "[1, 3]"}');
SELECT jcol, JSON_STORAGE_FREE(jcol) AS Size FROM jtable;
-- +----------------------------------------------+------+
-- | jcol | Size |
-- +----------------------------------------------+------+
-- | {"a": 1000, "b": "FYIcenter", "c": "[1, 3]"} | 0 |
-- +----------------------------------------------+------+
UPDATE jtable SET jcol = JSON_SET(jcol, "$.b", "FYI");
SELECT jcol, JSON_STORAGE_FREE(jcol) AS Size FROM jtable;
-- +----------------------------------------+------+
-- | jcol | Size |
-- +----------------------------------------+------+
-- | {"a": 1000, "b": "FYI", "c": "[1, 3]"} | 6 |
-- +----------------------------------------+------+
If you call JSON_STORAGE_FREE() will a JSON value, not a table column, it will returns 0. For example:
SELECT JSON_STORAGE_FREE('[100, "FYI", [1, 3, 5], 425.05]');
-- +------------------------------------------------------+
-- | JSON_STORAGE_FREE('[100, "FYI", [1, 3, 5], 425.05]') |
-- +------------------------------------------------------+
-- | 0 |
-- +------------------------------------------------------+
Reference information of the JSON_STORAGE_FREE() function:
JSON_STORAGE_FREE(json): int Returns the free space in a given JSON table column resulted from previous partial updates. Arguments, return value and availability: json: Required. The JSON table column to be examined. int: Return value. The the free space in the JSON column. Available since MySQL 8.0.
Related MySQL functions:
⇒ JSON_INSERT() - Inserting Members to JSON Value
⇐ JSON_EXTRACT() - Exacting Members from JSON
2024-12-18, 1625🔥, 0💬
Popular Posts:
Can Binary Strings Be Converted into NUMERIC or FLOAT Data Types in SQL Server Transact-SQL? Can bin...
How To Get the Definition of a User Defined Function Back in SQL Server Transact-SQL? If you want ge...
How To Calculate Age in Days, Hours and Minutes in SQL Server Transact-SQL? On many Web sites, news ...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...
How To Update Multiple Rows with One UPDATE Statement in SQL Server? If the WHERE clause in an UPDAT...