我在MariaDb中创建了一个包含动态列的表:
CREATE TABLE items (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
product varchar(100) NOT NULL,
data BLOB
);
INSERT INTO items (product, data) VALUES
('test_row',
COLUMN_CREATE('colour', 'blue',
'details',COLUMN_CREATE('key1','value1','key2','value2'))
);
但我无法以JSON格式提取嵌套对象,当我执行以下查询时,我得到一些二进制输出以获取详细信息字段:
SELECT product, COLUMN_GET(data, 'details' as CHAR(200)) AS Details
FROM items;
如何使用SQL查询解码此字段数据?
答案 0 :(得分:2)
使用此查询:
SELECT `product`, COLUMN_JSON(COLUMN_GET(`data`, 'details' AS BINARY)) AS Details
FROM `items`;