【问题标题】:Warning | 3156 | Invalid JSON value for CAST to INTEGER from column json_search at row 1 |警告 |第3156章从第 1 行的列 json_search 到 INTEGER 的 CAST 的 JSON 值无效 |
【发布时间】:2021-04-19 13:36:10
【问题描述】:

我的 JSON 示例

{"feeds": [{"trait": "Bankrupt", "rating": "medium", "observation": "mortgage problems", "riskscaling": "4"}, {"trait": "Incompetency", "rating": "high", "observation": "work problems", "riskscaling": "5"}, {"trait": "Mental Stress", "rating": "low", "observation": "personal problems", "riskscaling": "3"}], "ad_uidNumber": "2021041913", "ad_employeeID": "tom.banks"}

我收到错误

警告 |第3156章从第 1 行的 json_search 列中的 CAST 到 INTEGER 的 JSON 值无效 |

当我按 qry as 时

select distinct globalusers.id 
from globalusers 
where (JSON_SEARCH(dynamic_attributes->>'$.feeds[*].trait','all', 'Bankrupt'));

谁能帮帮我。

【问题讨论】:

    标签: mysql json


    【解决方案1】:
    select distinct id 
    from globalusers
    WHERE JSON_SEARCH(dynamic_attributes, 'all', 'Bankrupt', NULL, '$.feeds[*].trait') IS NOT NULL
    

    select distinct globalusers.id 
    from globalusers 
    where JSON_SEARCH(dynamic_attributes->>'$.feeds[*].trait','all', 'Bankrupt') IS NOT NULL
    

    或(数组取消引用没有意义)

    select distinct globalusers.id 
    from globalusers 
    where JSON_SEARCH(dynamic_attributes->'$.feeds[*].trait','all', 'Bankrupt') IS NOT NULL
    

    JSON_SEARCH 返回找到的路径或 NULL。

    警告 | 3156 |从第 1 行的 json_search 列中的 CAST 到 INTEGER 的 JSON 值无效 |

    是因为找到的不是从数字开始的路径无法正确转换为 BOOLEAN。

    【讨论】:

      猜你喜欢
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      相关资源
      最近更新 更多