小编Gab*_*tes的帖子

为什么 JSON_TABLE() 连接不一致?

在 MySQL 8 中,我们现在可以使用 JSON 类型列,还可以使用 JSON_TABLE() 等内置函数,但当我在不同的场景中使用时,有时我会看到意想不到的结果。

JSON_TABLE() 的文档:https ://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html

也许 JSON_TABLE 不是完成连接一段 JSON 的方法。MySQL 提供了一些搜索功能,但我没有想到可以替代 JSON_TABLE()

JSON 搜索函数的文档:https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html

架构(MySQL v8.0)

CREATE TABLE USER (
    NAME varchar(128) NOT NULL,
    METADATA JSON NULL
);

INSERT INTO USER VALUES
('John', '[1,3]'),
('Jane', '[2]'),
('Bob', null),
('Sally', '[9]');


CREATE TABLE ROLES (
  ID int NOT NULL,
  NAME varchar(64) NOT NULL
);

INSERT INTO ROLES VALUES
(1, 'Originator'),
(2, 'Approver'),
(3, 'Reviewer');
Run Code Online (Sandbox Code Playgroud)

问题 #1 - 为什么 Bob 没有返回?

SELECT * 
FROM …
Run Code Online (Sandbox Code Playgroud)

json mysql-8.0

5
推荐指数
1
解决办法
4571
查看次数

标签 统计

json ×1

mysql-8.0 ×1