sql - How to extract a value from JSON column with MariaDB, being this not an exact value in the JSON field?
问题描述
I need to extract a field from a JSON string with MariaDB and search for specific patterns in that field.
This field is just a property of all the properties the JSON object has. I had read the documentation and I saw the JSON_EXTRACT
function. I am still a newbie with databases so I would like some help in this matter.
{"user_id":"1","status_id":"1","text":"Hello, world"}
Lets say I want to get all the "text" values that have the "world" in the database table. I can extract with JSON_EXTRACT
. But I want patterns, not absolute values.
How can I do that?
解决方案
You can extract the value with json_extract()
, and then do pattern matching with like
:
select t.*
from mytable t
where json_extract(my_json_col, '$.text') like '%world%'
推荐阅读
- intellij-idea - 错误:在 IntelliJ 上创建 JavaFX 项目时找不到或加载主类 sample.Main
- c++ - MATLAB 中的可变大小数组:如何从 MATLAB 生成可变大小数组?
- javascript - jwt.verify() 在过期时间为 24h 时返回 jwt expired
- c++ - 为什么将 std::make_pair 传递给 map::insert 不起作用?
- c - C 主函数应该返回什么?EXIT_SUCCESS 还是 0?
- android - Google 登录在 iOS 上不返回姓名、图片、名字、姓氏,但在 Android 上有效
- php - JWT 无法仅在实时站点上从请求中解析令牌
- javascript - 发送多封电子邮件时显示进度
- semantic-ui - 使用语义 UI 的可见性在溢出的 div 中进行无限滚动
- windows - 如何在 vbscript 中使用字符串变量作为 telnet 命令?