我尝试构建一个返回 json 的函数。
我将 mysql Workbench 更新到 8.0.14 并尝试了以下代码:
SELECT JSON_OBJECT(
'name_field', name_field,
'address_field', address_field,
'contact_age', contact_age
)
FROM contact;
但出现以下错误:
Error Code: 1305. FUNCTION datalog.json_object does not exist
我认为 json_object 是一个标准的 mysql 函数,不是吗?
看这里: JSON Object
最佳答案
您使用的是 MariaDB,而不是 MySQL,您的版本 (MariaDB 10.1) 与 MySQL 5.7 大致相当,但有一些重要的差异。您的工作台版本无关紧要 - 重要的是服务器版本。
https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/
MariaDB 10.1 and above does not support MySQL 5.7's packed JSON objects. MariaDB follows the SQL standard and stores the JSON as a normal TEXT/BLOB. If you want to replicate JSON columns from MySQL to MariaDB, you should store JSON objects in MySQL in a TEXT column or use statement based replication. If you are using JSON columns and want to upgrade to MariaDB, you can either convert the JSON columns to TEXT or use mysqldump to copy these tables to MariaDB. In MySQL, JSON is compared according to json values. In MariaDB JSON strings are normal strings and compared as strings.
MariaDB 10.2.3 添加了 JSON_OBJECT 支持。 https://mariadb.com/kb/en/library/json_object/
关于mysql - 函数 json_object 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54446913/