为什么 select json 数据在 mariadb 中不起作用?
Why select json data not working in the mariadb?
我的查询是这样的:
select `information`->'$."full_name"' as `homeroom`
from `classes`
如果在我的本地数据库中查询 运行,它会起作用。没有错误
但是如果在我的数据库服务器中查询运行,它就不起作用。存在这样的错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."full_name"' as `homeroom`
from `classes` LIMIT 0, 25' at line 1
如果我运行 select version()
,
我的本地版本数据库:8.0.15
我的版本数据库服务器:10.0.38-MariaDB
似乎它不起作用,因为我的数据库服务器使用 mariadb
我该如何解决这个问题?
更新:
我在信息字段中使用数据类型文本
JSON 函数直到版本 10.2.3 才添加到 MariaDB。如果您无法升级,您将不得不处理应用程序中的数据。请注意,即使在支持 JSON 的版本中,它们也不支持 ->
表示法 (reference),因此您必须将查询重写为
JSON_EXTRACT(information, '$.full_name')
我的查询是这样的:
select `information`->'$."full_name"' as `homeroom`
from `classes`
如果在我的本地数据库中查询 运行,它会起作用。没有错误
但是如果在我的数据库服务器中查询运行,它就不起作用。存在这样的错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."full_name"' as `homeroom`
from `classes` LIMIT 0, 25' at line 1
如果我运行 select version()
,
我的本地版本数据库:8.0.15
我的版本数据库服务器:10.0.38-MariaDB
似乎它不起作用,因为我的数据库服务器使用 mariadb
我该如何解决这个问题?
更新:
我在信息字段中使用数据类型文本
JSON 函数直到版本 10.2.3 才添加到 MariaDB。如果您无法升级,您将不得不处理应用程序中的数据。请注意,即使在支持 JSON 的版本中,它们也不支持 ->
表示法 (reference),因此您必须将查询重写为
JSON_EXTRACT(information, '$.full_name')