【发布时间】:2016-08-11 17:36:19
【问题描述】:
JSON/MEMSQL 有问题。这是我的桌子:
CREATE TABLE `MEMSQLPOLYGLOT` (
ID BIGINT AUTO_INCREMENT,
`DATA` JSON NULL,
PRIMARY KEY (ID)
);
这是我要阅读的记录:
insert into MEMTEST (DATA) values
('
{
"EnterpriseMessage" :
{
"Body" :
[
{
"AccountNumber":"ABCD",
"AdminCompany":null,
"BrokerNumber":"WWonka"
},
{
"AccountNumber":"CSNE",
"AdminCompany":null,
"BrokerNumber":"ZWiza"
}
],
"Header" :
{
"mimetye":"application/vnd.ms-powerpoint",
"destinationsystem":"ETL",
"requiresack":"FALSE",
"SimpArr":
[
"BYTS6181",
"EVU98124",
"Genesys"
],
"EmptyFile":1
}
}
}
');
我可以读取标题中的 SimpArr 数组。
SELECT DATA::EnterpriseMessage::Header::SimpArr from MEMTEST;
返回:
["BYTS6181","EVU98124","Genesys"]
我也可以传入一个键索引来获取特定的值,比如:
select JSON_EXTRACT_JSON(DATA::EnterpriseMessage::Body, 1) from MEMTEST;
这将返回 SimpArr 的第二个值,因为它是从零开始的索引。
我还可以读取 Body 中的对象数组:
select JSON_EXTRACT_JSON(DATA::EnterpriseMessage::Body, 0) from MEMTEST;
返回该数组中的第一个对象:
{
"AccountNumber":"ABCD",
"AdminCompany":null,
"BrokerNumber":"WWonka"
}
但是,我无法找到读取此对象的各个属性的方法。
有人有什么想法吗?
【问题讨论】:
标签: json singlestore