从Mariadb中的动态列字段中提取嵌套对象

时间:2015-08-28 08:41:02

标签: mysql json mariadb

我在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查询解码此字段数据?

1 个答案:

答案 0 :(得分:2)

使用此查询:

SELECT `product`, COLUMN_JSON(COLUMN_GET(`data`, 'details' AS BINARY)) AS Details
FROM `items`;