我的问题是关于在mysql的json数据类型中搜索JSON数组的内容。
DB结构
因此,如果我在mysql表中有两行,并且有一个名为foo的json字段。
第一行包含:
{
"items": [
{"type": "bar"}
]
}第二行包含:
{
"items": [
{"type": "baz"}
]
}可以工作的东西
我能跑
select `foo`->"$.items[0].type" from `jsontest`返回2个结果:bar和baz
我能跑
select `id` from `jsontest` where `foo`->"$.items[0].type" = "bar"返回1个结果:1 - ie。第一行的id。
我的问题
可以使用[*]来“计算出JSON数组中所有元素的值”的mysql docs state。
但是,以下查询返回零个项目:
select `id` from `jsontest` where `foo`->"$.items[*].type" = "bar"我的查询有什么问题?
发布于 2016-07-30 05:09:13
执行以下查询:
select id, `foo`->"$.items[*].type[0]" from `jsontest`;您会注意到返回值显示为"bar",这是JSON数组。
select * from `jsontest`
where `foo`->"$.items[*].type" = JSON_ARRAY('bar');无论如何,下面的查询也应该有效:
select id from `jsontest` where JSON_SEARCH(`foo`, 'all','bar') is not null;https://stackoverflow.com/questions/38657793
复制相似问题