【问题标题】:How to search JSON array contains item in mysql如何搜索JSON数组包含mysql中的项目
【发布时间】:2021-01-21 19:34:25
【问题描述】:

我的数据库中有类型图像 (json)。它的字符串数组。

如何选择images 包含"foo" 的所有行?

【问题讨论】:

    标签: mysql sql arrays json where-clause


    【解决方案1】:

    使用json_contains():

    select t.*
    from mytable t
    where json_contains(images, '"foo"')
    

    【讨论】:

    • 它抛出Invalid JSON text in argument 2 to function json_contains: "Invalid value." at position 1.
    • @sayicej101:我的错,看起来我们需要在值周围加上双引号。查看我的更新。
    猜你喜欢
    • 2018-04-24
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    相关资源
    最近更新 更多