我已經有了對象的JSON列表一樣,MySQL的json_search
[{
"something": "bla",
"id": 2
}, {
"something": "yes",
"id": 1
}]
我id
領域始終是一個數值。但是,當我試圖找到id = 2
,則MySQL返回NULL
select
json_search(
json_extract(
'[{"something": "bla" ,"id": 2}, {"something": "yes","id": 1}]',
"$[*].id"
),
'one',
2
) as json_search;
json_search |
------------|
|
當我在我的JSON id
對象,而不是一個數值,使用一個字符串作爲值,我得到了與指數0
select
json_search(
json_extract(
'[{"something": "bla" ,"id": "2"}, {"something": "yes","id": 1}]',
"$[*].id"
),
'one',
"2"
) as json_search;
json_search |
------------|
"$[0]" |
結果
我使用的是MySQL 5.7.17
@@version |
-----------|
5.7.17-log |
是JSON陣列數字搜索不是MySQL提供的?
但後來我不得不使用字符串值作爲搜索值...還算不上令人滿意 – Markus