简体   繁体   中英

Max size of JSON column in MySQL 5.7

Given this table in a MySQL 5.7 database mydb :


CREATE TABLE `foo` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `stuff` json DEFAULT NULL,
  PRIMARY KEY (`id`)
)

How would I get the maximum size of the data in the stuff column? Not the maximum possible size, but the maximum current size across all rows in the table. I've tried SELECT max(JSON_STORAGE_SIZE(stuff)) from foo , but I get the error ERROR 1305 (42000): FUNCTION mydb.json_storage_size does not exist .

You can get an approximate length by querying it as a string:

SELECT MAX(LENGTH(stuff)) FROM foo

This may not match the JSON_STORAGE_SIZE() though.

The JSON_STORAGE_SIZE() function was added in MySQL 5.7.22. If you have an older version, you can't use that function unless you upgrade.

The error you saw indicates that MySQL doesn't know it as a builtin function, so it's trying to execute it as if you had create a stored function by that name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM