mysql - 函数 json_object 不存在

标签 mysql sql json

我尝试构建一个返回 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/

相关文章:

sql - 插入的数据未使用直接查询显示在 Oracle 数据库中

java - 使用不同关键字将 JSON 映射到 Java 对象

java - Gradle 项目 --Failed to configure a DataSource'url' attribute is not specified and no embedded datasource could be configured

没有单独的 SELECT 查询的 PHP MySQL 更新减去变量

php - 通过优先级在单个 Laravel 查询中进行多选择查询

jquery - 检查是否允许使用jQuery嵌入YouTube视频

带有 bool 值的 MySQL JSON_SEARCH 不起作用

java - 如何从方法返回所有结果集值。 java

javascript - 标题在页面加载之前重定向,但仍然运行 SQL

sql - 更新触发器更新目标中的所有行,而不仅仅是更新?