mysql json_contains 可以不区分大小写吗?

dyl*_*anw 3 mysql sql json

我希望能够“搜索”不区分大小写json_contains

这是 json 示例:

[
  {
    "title": "foo Bar",
    "author": "melaine"
  },
  {
    "title": "incredible",
    "author": "steve"
  }
]
Run Code Online (Sandbox Code Playgroud)

我尝试过的:

SELECT json_contains('[{"title":"foo Bar", "authour": "melaine"}, {"title":"foo barius", "authour": "steve"}]', '{"title":"foo bar"}')
Run Code Online (Sandbox Code Playgroud)

预期结果:1

真实结果:0

因为我查找“foo bar”并且 json 中的值为“foo Bar”,所以我没有得到匹配项。有没有办法让这种情况不敏感,这样我就能得到匹配?

Mad*_*iya 8

您可以使用函数将 JSON (haystack) 和搜索块 (needle) 转换为小写LOWER(),以进行不区分大小写的搜索:

SELECT json_contains(LOWER('[{"title":"foo Bar", "authour": "melaine"}, {"title":"foo barius", "authour": "steve"}]'), 
                     LOWER('{"title":"foo bar"}'))
Run Code Online (Sandbox Code Playgroud)

DB 小提琴演示