Jos*_*nce 13 postgresql json jsonb
我有一个params名为reports包含JSON 的表中的列.
我需要在JSON数组中的任何位置找到哪些行包含文本'authVar'.我不知道文本出现的路径或级别.
我想用标准的操作符搜索JSON.
就像是:
SELECT * FROM reports
WHERE params LIKE '%authVar%'
Run Code Online (Sandbox Code Playgroud)
我搜索并搜索了Postgres文档.我不太了解JSON数据类型,并且我错过了一些简单的东西.
JSON看起来像这样.
[
{
"tileId":18811,
"Params":{
"data":[
{
"name":"Week Ending",
"color":"#27B5E1",
"report":"report1",
"locations":{
"c1":0,
"c2":0,
"r1":"authVar",
"r2":66
}
}
]
}
}
]
Run Code Online (Sandbox Code Playgroud)
kli*_*lin 20
可以递归地遍历未知的json结构,但它会相当复杂和昂贵.我会提出应该运作良好的蛮力方法:
select *
from reports
where params::text like '%authVar%';
-- or
-- where params::text like '%"authVar"%';
-- if you are looking for the exact value
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6538 次 |
| 最近记录: |