【问题标题】:Check if value exists exactly like that with SQL query (regexp)?检查值是否与 SQL 查询(正则表达式)完全相同?
【发布时间】:2022-11-02 05:43:07
【问题描述】:

社交媒体数据库列中的示例 json

[{"id":"1463dae5-1168-432e-8e55-c61820d69c49","value":"person2"}, 
{"id":"c61820d69c49-8e55-432e-8e55-8e55","value":"person1"}]

我想运行一个查询来检查json字段中是否存在“value”:“person1”或“value:”person2”或其他类似的东西。这可能与正则表达式或其他东西有关吗?

【问题讨论】:

标签: sql laravel postgresql eloquent


【解决方案1】:

使用JSON_SEARCH

AppModelsUser::whereRaw('JSON_SEARCH(users.name, "all", "%person%")')->get();

或使用JSON_EXTRACT

AppModelsUser::where(DB::raw('JSON_EXTRACT(`name`, "$.*")'), 'LIKE', '%person%')->get();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 2016-03-15
    • 2013-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多